different-ai/openwork · error · Error

Invalid proxy URL: ${raw}

Error message

Invalid proxy URL: ${raw}

What it means

parseBrowserProxyInput prepends http:// if no scheme is present, then runs the result through the URL constructor; if parsing fails the raw input is thrown back in this error. The proxy string is not a parsable URL.

Source

Thrown at apps/desktop/electron/browser-panel.mjs:434

  function resolveBrowserProxyInput(input) {
    const raw = String(input ?? "").trim();
    const envMatch = raw.match(/^env:([A-Za-z0-9_]+)$/i);
    if (!envMatch) return raw;
    const key = `OPENWORK_BROWSER_PROXY_${envMatch[1].toUpperCase()}`;
    const value = String(process.env[key] ?? "").trim();
    if (!value) throw new Error(`No proxy configured: set the ${key} environment variable to a proxy URL.`);
    return value;
  }

  function parseBrowserProxyInput(input) {
    const raw = resolveBrowserProxyInput(input);
    if (!raw) return null;
    const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw) ? raw : `http://${raw}`;
    let url;
    try {
      url = new URL(withScheme);
    } catch {
      throw new Error(`Invalid proxy URL: ${raw}`);
    }
    if (!url.hostname || !url.port) {
      throw new Error("Proxy must include host and port, e.g. http://user:pass@host:8080 or socks5://host:1080.");
    }
    const scheme = url.protocol.replace(/:$/, "").toLowerCase();
    return {
      rules: `${scheme}://${url.hostname}:${url.port}`,
      username: decodeURIComponent(url.username),
      password: decodeURIComponent(url.password),
    };
  }

  function browserProxyState() {
    return {
      proxy: browserProxy
        ? { rules: browserProxy.rules, authenticated: Boolean(browserProxy.username) }
        : null,
    };

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Provide a full valid URL, e.g. http://user:pass@host:8080 or socks5://host:1080
  2. Trim surrounding whitespace and quotes from the configured value
  3. If omitting scheme, use the host:port form so the implicit http:// prefix yields a valid URL
  4. Inspect the resolved env value (when using env:VAR) — the bad string may come from the variable, not the config

Example fix

// before
proxy: 'http://'
// after
proxy: 'http://proxy.corp.local:8080'
Defensive patterns

Strategy: validation

Validate before calling

function isValidProxyInput(raw) {
  let s = String(raw ?? '').trim();
  if (!s) return true;
  if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(s)) s = `http://${s}`;
  try { const u = new URL(s); return Boolean(u.hostname && u.port); } catch { return false; }
}

Type guard

function isParsableProxyUrl(raw) {
  try {
    const s = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw) ? raw : `http://${raw}`;
    return new URL(s) instanceof URL;
  } catch { return false; }
}

Try / catch

try {
  panel = createBrowserPanel({ proxy: proxyInput });
} catch (e) {
  if (e.message.startsWith('Invalid proxy URL:')) {
    // show the offending value and the expected format, disable browser panel
  } else throw e;
}

Prevention

When it happens

Trigger: Passing malformed proxy values like 'http://host' (unparseable due to bad characters), 'host:port:extra', strings with spaces, or an env-resolved value that is not a URL (e.g. a bare 'proxy.corp' with no host:port shape the URL parser accepts).

Common situations: Copy-paste errors with hidden whitespace or smart quotes; forgetting both scheme and port ('myproxy.corp' becomes http://myproxy.corp which has no port — that throws the NEXT error, so this one is usually true syntax garbage like 'http://'); quoting issues in shell env vars.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/895e37c9402b9513. Report an issue: GitHub.