{"record":{"id":"366c9e7da52b3328","repo":"sveltejs/kit","slug":"dev-cannot-use-caller-with-an-external-url","errorCode":null,"errorMessage":"DEV: Cannot use `${caller}` with an external URL. Use `window.location = \"${url}\"` instead | PROD: ${caller}: invalid URL","messagePattern":"DEV: Cannot use `(.+?)` with an external URL\\. Use `window\\.location = \"(.+?)\"` instead \\| PROD: (.+?): invalid URL","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/client/client.js","lineNumber":2643,"sourceCode":"\tif (updating || !started) {\n\t\tautoscroll = false;\n\t}\n}\n\nlet warned_on_invalidate_all = false;\nlet warned_on_replace_state = false;\nlet warned_on_push_state = false;\nlet warned_on_replace_state_function = false;\n\n/**\n * @param {string | URL} url\n * @param {'goto' | 'pushState' | 'replaceState'} caller\n */\nasync function resolve_intent(url, caller) {\n\tconst resolved = new URL(resolve_url(url));\n\n\tif (resolved.origin !== origin) {\n\t\tthrow new Error(\n\t\t\tDEV\n\t\t\t\t? `Cannot use \\`${caller}\\` with an external URL. Use \\`window.location = \"${url}\"\\` instead`\n\t\t\t\t: `${caller}: invalid URL`\n\t\t);\n\t}\n\n\tconst intent = await get_navigation_intent(resolved, false);\n\n\tif (!intent) {\n\t\tthrow new Error(\n\t\t\tDEV\n\t\t\t\t? `Cannot use \\`${caller}\\` with a URL that does not resolve to a route within the app. Use \\`window.location = \"${url}\"\\` instead`\n\t\t\t\t: `${caller}: invalid URL`\n\t\t);\n\t}\n\n\treturn intent;\n}","sourceCodeStart":2625,"sourceCodeEnd":2661,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/client.js#L2625-L2661","documentation":"resolve_intent() validates that every client-side navigation target is a same-origin URL that resolves to a route in the app. External origins are disallowed because SvelteKit's client router cannot manage a full page load to another origin. In production the message is minified to `${caller}: invalid URL` to keep bundles small.","triggerScenarios":"Calling goto('https://other-site.com'), pushState()/replaceState() with a URL whose origin differs from `origin`, or a base-relative URL that resolves to an external origin (e.g. wrong `paths.base` config producing an absolute external URL).","commonSituations":"Redirecting to an OAuth provider or payment gateway via goto(); concatenating API base URLs into goto(); misconfigured svelte.config.js paths or PRerendered absolute links; code migrated from an app that used location.href-style strings.","solutions":["Use window.location = url (or window.location.href = url) for external URLs","Verify the URL origin matches window.location.origin before calling goto/pushState/replaceState","Fix svelte.config.js paths.base / paths.assets so internal links resolve same-origin","In production, decode the short message: `${caller}: invalid URL` means an external or unroutable URL was passed"],"exampleFix":"// before\nawait goto('https://example.com/checkout');\n// after\nwindow.location.href = 'https://example.com/checkout';","handlingStrategy":"validation","validationCode":"function isInternalUrl(url) {\n  const u = new URL(url, location.href);\n  return u.origin === location.origin;\n}\n// call goto only if isInternalUrl(target)","typeGuard":"function isSameOrigin(u) { try { return new URL(u, location.href).origin === location.origin; } catch { return false; } }","tryCatchPattern":"try { await goto(url); } catch (e) { if (String(e.message).includes('invalid URL') || e.message.includes('external URL')) { window.location.href = url; } else { throw e; } }","preventionTips":["Check origin equality before any programmatic navigation","Use window.location for all off-site redirects","Audit svelte.config.js paths when deploying under a base path"],"tags":["navigation","routing","sveltekit"],"backgroundTag":"external-url-navigation","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}