{"record":{"id":"5e949eaa6a62edb1","repo":"denoland/deno","slug":"request-mode-navigate-is-not-allowed","errorCode":null,"errorMessage":"Request mode 'navigate' is not allowed","messagePattern":"Request mode 'navigate' is not allowed","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/fetch/23_request.js","lineNumber":450,"sourceCode":"          (parsedReferrer.protocol === \"about:\" &&\n            parsedReferrer.pathname === \"client\")\n        ) {\n          request.referrer = \"client\";\n        } else {\n          request.referrer = parsedReferrer.href;\n        }\n      }\n    }\n\n    // 18. referrerPolicy\n    if (init.referrerPolicy !== undefined) {\n      request.referrerPolicy = init.referrerPolicy;\n    }\n\n    // 19. mode\n    if (init.mode !== undefined) {\n      if (init.mode === \"navigate\") {\n        throw new TypeError(\"Request mode 'navigate' is not allowed\");\n      }\n      request.mode = init.mode;\n    }\n\n    // 20. credentials\n    if (init.credentials !== undefined) {\n      request.credentialsMode = init.credentials;\n    }\n\n    // 21. cache\n    if (init.cache !== undefined) {\n      request.cacheMode = init.cache;\n    }\n\n    // If request's cache mode is \"only-if-cached\" and request's mode is not\n    // \"same-origin\", then throw a TypeError.\n    if (\n      request.cacheMode === \"only-if-cached\" && request.mode !== \"same-origin\"","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/fetch/23_request.js#L432-L468","documentation":"The fetch spec only allows RequestInit.mode values \"same-origin\", \"cors\", \"no-cors\", and \"navigate\" — but \"navigate\" is reserved for browser navigation and explicitly rejected in the Request constructor step 19. Passing init.mode === \"navigate\" throws TypeError \"Request mode 'navigate' is not allowed\".","triggerScenarios":"new Request(url, { mode: \"navigate\" }); mode values forwarded from a UI/config that lets users pick any spec-listed mode.","commonSituations":"Copy-pasting browser navigation code into a Deno worker; config schemas that enumerate the four spec modes including navigate; attempting to fetch a page \"as a navigation\" to get no-CORS semantics.","solutions":["Remove mode: \"navigate\" — omit mode entirely (defaults to \"cors\")","Use \"same-origin\", \"cors\", or \"no-cors\" as appropriate","Drop \"navigate\" from any user-selectable mode list in your config"],"exampleFix":"// before\nnew Request(\"https://example.com/page\", { mode: \"navigate\" }); // throws\n\n// after\nnew Request(\"https://example.com/page\", { mode: \"no-cors\" }); // pick a real mode\n// or simply omit it:\nnew Request(\"https://example.com/page\");","handlingStrategy":"validation","validationCode":"const ALLOWED_MODES = new Set([\"same-origin\", \"cors\", \"no-cors\"]);\nconst mode = ALLOWED_MODES.has(init.mode) ? init.mode : undefined;\nconst req = new Request(url, { ...init, mode });","typeGuard":"const ALLOWED_MODES = new Set([\"same-origin\", \"cors\", \"no-cors\"]);\nfunction isAllowedRequestMode(m: unknown): boolean {\n  return m === undefined || (typeof m === \"string\" && ALLOWED_MODES.has(m));\n}","tryCatchPattern":"try {\n  new Request(url, { mode });\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes(\"navigate\")) {\n    new Request(url); // mode omitted, defaults to cors\n  } else throw err;\n}","preventionTips":["Remove 'navigate' from mode enums in config schemas and UIs","Treat mode as optional — the default ('cors') is right for most server-side fetches","Note mode interacts with cache: 'only-if-cached' requires 'same-origin'"],"tags":["fetch","request","mode"],"backgroundTag":"invalid-request-mode","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}