musistudio/claude-code-router · error · Error
Origin redirected to ${loadedOrigin}.
Error message
Origin redirected to ${loadedOrigin}. What it means
Thrown when a hidden BrowserWindow loaded for localStorage import ends up on a different origin than requested (e.g. the site redirects HTTP->HTTPS or to a canonical domain). The import writes localStorage entries via executeJavaScript on the loaded origin, so a redirect would silently write credentials into the wrong origin's storage and the guard aborts.
Source
Thrown at packages/electron/src/main/chrome-login-import.ts:371
height: 480,
paintWhenInitiallyHidden: true,
show: false,
skipTaskbar: true,
title: "CCR Chrome Login Import",
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
partition,
sandbox: true,
webSecurity: true
},
width: 640
});
try {
await withTimeout(window.webContents.loadURL(`${origin}/`), localStorageWriteTimeoutMs, "Timed out loading localStorage origin.");
const loadedOrigin = new URL(window.webContents.getURL()).origin;
if (loadedOrigin !== origin) {
throw new Error(`Origin redirected to ${loadedOrigin}.`);
}
const entries = Object.entries(items);
await window.webContents.executeJavaScript(
`(() => {
const entries = ${JSON.stringify(entries)};
for (const [key, value] of entries) {
window.localStorage.setItem(key, value);
}
return entries.length;
})()`,
true
);
} finally {
if (!window.isDestroyed()) {
window.destroy();
}
}
}View on GitHub (pinned to 99f24806c6)
Solutions
- Re-export the login state from Chrome while browsing the exact final origin (scheme + host + www) and re-import
- Normalize/upgrade origins in the payload to the final redirect target before importing
- If the redirect is expected and trusted, pre-resolve the origin (follow the redirect once yourself) and rewrite the payload's origin field
Example fix
// before
localStorage: [{ origin: "http://example.com", items: {...} }]
// after
localStorage: [{ origin: "https://www.example.com", items: {...} }] Defensive patterns
Strategy: validation
Validate before calling
import { looksLikeHttpUrl } from './url.js';
function assertStableOrigin(origin: string): void {
if (!looksLikeHttpUrl(origin)) throw new Error(`Invalid origin: ${origin}`);
const res = await fetch(origin, { method: 'HEAD', redirect: 'manual' });
if (res.status >= 300 && res.status < 400) {
throw new Error(`Origin ${origin} redirects to ${res.headers.get('location')}`);
}
} Type guard
function isHttpOrigin(value: string): boolean {
try { const u = new URL(value); return u.protocol === 'http:' || u.protocol === 'https:'; }
catch { return false; }
} Try / catch
try {
await importLoginState(payload);
} catch (err) {
if (err instanceof Error && err.message.startsWith('Origin redirected to ')) {
const target = err.message.slice('Origin redirected to '.length).replace(/\.$/, '');
payload.localStorage.forEach(i => i.origin = target);
await importLoginState(payload); // retry once with final origin
} else throw err;
} Prevention
- Export login state while on the exact final HTTPS origin
- Normalize origins (upgrade http->https, add www) before import
- Catch the redirect error and retry once with the reported target origin
When it happens
Trigger: Calling the Chrome login import with a localStorage item whose origin is e.g. http://example.com but which 301-redirects to https://www.example.com; loadURL succeeds but getURL().origin differs from the requested origin.
Common situations: Imported Chrome localStorage entries recorded under http:// or apex domains while the live site enforces HTTPS/WWW redirects; typos in the origin string; sites that redirect to a login/locale subdomain.
Related errors
- ZCode profiles can only open the app; agent arguments are no
- Claude App profiles do not support agent arguments.
- Failed to open Claude App: ${spawnError}
- Failed to open ZCode App: ${spawnError}
- Unable to load @the-next-ai/bot-gateway-sdk. ${errors.join("
AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27).
Data as JSON: /api/errors/1d05dd3fdb2600a3.
Report an issue: GitHub.