denoland/deno · error · TypeError
Request mode 'navigate' is not allowed
Error message
Request mode 'navigate' is not allowed
What it means
Request constructor step 19 rejects init.mode === 'navigate' with TypeError 'Request mode 'navigate' is not allowed'. Navigate mode is reserved for browser document loads and cannot be created from script per the Fetch spec; all other mode values ('same-origin', 'cors', 'no-cors') pass through unvalidated here.
Source
Thrown at ext/fetch/23_request.js:450
(parsedReferrer.protocol === "about:" &&
parsedReferrer.pathname === "client")
) {
request.referrer = "client";
} else {
request.referrer = parsedReferrer.href;
}
}
}
// 18. referrerPolicy
if (init.referrerPolicy !== undefined) {
request.referrerPolicy = init.referrerPolicy;
}
// 19. mode
if (init.mode !== undefined) {
if (init.mode === "navigate") {
throw new TypeError("Request mode 'navigate' is not allowed");
}
request.mode = init.mode;
}
// 20. credentials
if (init.credentials !== undefined) {
request.credentialsMode = init.credentials;
}
// 21. cache
if (init.cache !== undefined) {
request.cacheMode = init.cache;
}
// If request's cache mode is "only-if-cached" and request's mode is not
// "same-origin", then throw a TypeError.
if (
request.cacheMode === "only-if-cached" && request.mode !== "same-origin"View on GitHub (pinned to 89f33cbef2)
Solutions
- Remove the mode: 'navigate' option entirely (default mode is usually 'cors')
- Use 'same-origin', 'cors', or 'no-cors' as appropriate
- Strip unknown/unsupported keys in generic fetch wrappers before constructing Request
Example fix
// before
await fetch(url, { mode: 'navigate' });
// after
await fetch(url, { mode: 'cors' }); Defensive patterns
Strategy: validation
Validate before calling
const MODES = new Set(['same-origin', 'cors', 'no-cors']);
function normalizeMode(mode) {
if (mode == null) return undefined;
const m = String(mode);
if (!MODES.has(m)) throw new Error(`unsupported mode: ${m} (navigate is not allowed)`);
return m;
} Type guard
/** @param {unknown} m */
function isAllowedRequestMode(m) {
return m == null || ['same-origin', 'cors', 'no-cors'].includes(m);
} Prevention
- Never forward mode values copied from specs or browser internals
- Strip mode from option bags of generic wrappers unless explicitly supported
- Remember default mode is 'cors' — usually you can omit it
When it happens
Trigger: new Request(url, { mode: 'navigate' }) or fetch(url, { mode: 'navigate' }).
Common situations: Porting browser code or specs that mention navigate mode, generic option-forwarding wrappers that copy a mode value from elsewhere, or confusion between request.mode and navigation concepts.
Related errors
- Method is forbidden
- Invalid header: length must be 2, but is ${header.length}
- Cannot read headers: request closed
- cannot read url: request closed
- Cannot read url: request closed
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/5e949eaa6a62edb1.
Report an issue: GitHub.