yikart/AiToEarn · error · Error

PLUGIN_PROXY_REQUEST_UNAVAILABLE

Error message

PLUGIN_PROXY_REQUEST_UNAVAILABLE

What it means

proxyRequest resolves the extension's proxyRequest method via getPluginProxyMethod() and throws the sentinel Error 'PLUGIN_PROXY_REQUEST_UNAVAILABLE' when window.AIToEarnPlugin or its proxyRequest function is absent. The plugin proxy is the only channel for cross-origin requests the extension performs on behalf of the page, so without it any proxied call cannot proceed.

Source

Thrown at project/aitoearn-web/src/store/plugin/request.ts:13

/**
 * 插件通用代理请求封装
 */

import type { PluginProxyRequestParams, PluginProxyResponse } from './types/baseTypes'

const PLUGIN_PROXY_REQUEST_UNAVAILABLE = 'PLUGIN_PROXY_REQUEST_UNAVAILABLE'

function getPluginProxyMethod() {
  const plugin = typeof window !== 'undefined' ? window.AIToEarnPlugin : undefined

  if (!plugin?.proxyRequest) {
    throw new Error(PLUGIN_PROXY_REQUEST_UNAVAILABLE)
  }

  return plugin.proxyRequest.bind(plugin)
}

export async function proxyRequest(params: PluginProxyRequestParams): Promise<PluginProxyResponse> {
  return getPluginProxyMethod()(params)
}

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Install/update the Aitoearn extension to a version exposing proxyRequest, then reload the page.
  2. Guard calls: check `window.AIToEarnPlugin?.proxyRequest` before invoking proxyRequest and fall back to a direct fetch or an install prompt.
  3. Catch the sentinel error by comparing err.message === 'PLUGIN_PROXY_REQUEST_UNAVAILABLE' and route to plugin-setup UX.
  4. Avoid calling proxyRequest in non-browser contexts; add a typeof window check at the call site.

Example fix

// before
const res = await proxyRequest({ url, method: 'GET' })

// after
if (typeof window === 'undefined' || !window.AIToEarnPlugin?.proxyRequest) {
  return fallbackDirectRequest({ url, method: 'GET' })
}
const res = await proxyRequest({ url, method: 'GET' })
Defensive patterns

Strategy: fallback

Validate before calling

export function canProxy(): boolean {
  return typeof window !== 'undefined' && typeof window.AIToEarnPlugin?.proxyRequest === 'function'
}
if (!canProxy()) return fallbackDirectRequest(params)

Type guard

function hasProxyRequest(p: unknown): p is { proxyRequest: (params: PluginProxyRequestParams) => Promise<PluginProxyResponse> } {
  return !!p && typeof (p as any).proxyRequest === 'function'
}

Try / catch

try {
  return await proxyRequest(params)
}
catch (e) {
  if (e.message === 'PLUGIN_PROXY_REQUEST_UNAVAILABLE')
    return fallbackDirectRequest(params)
  throw e
}

Prevention

When it happens

Trigger: Calling proxyRequest(params) (or anything built on it) in an environment where window.AIToEarnPlugin is undefined, or the plugin object exists but does not expose proxyRequest (old extension version predating the API).

Common situations: Extension not installed/disabled; page loaded before the extension content script ran; extension is an older build lacking proxyRequest; code path executed during SSR where window is undefined.

Related errors


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/b7da5974e36ec686. Report an issue: GitHub.