Skip to main content
fetch is global. It reads method / headers / body / signal from the init object and returns a Promise<Response>. Everything else in init (timeout, redirect) is ignored. Method names are exact-case standard tokens — lowercase "post" is sent as GET (see Troubleshooting).

Permissions

Outbound requests are deny-by-default. Every fetch needs --allow-net for the destination:
  • The URL’s literal host is matched, lowercased. There is no DNS lookup and no IP matching: localhost ≠ 127.0.0.1, and granting api.example.com does not cover 93.184.216.34.
  • Ports matter. https://api.example.com/ checks api.example.com:443; http://api.example.com/ checks api.example.com:80. Omit the port in the flag to allow every port on that host.
  • *.example.com matches subdomains but not the apex example.com. * (or bare --allow-net) grants every host and port.
  • Every redirect hop is checked again against the new URL.
  • TLS trust (--ca, FF_CA_FILE) is separate and does not grant network access. Proxy variables are read by the runtime without --allow-env, and the check applies to the destination, not the proxy host — see fetch Proxies.
An initial URL outside the scope throws synchronously:
A redirect hop outside the scope rejects with a string instead: "PermissionDenied: fetch requires --allow-net". Catch both shapes. Full model: Permissions.

Quick look

Modules vs scripts

ff forces ES module evaluation when a file ends in .mjs. For .js files, ff tries classic-script compilation first and automatically falls back to ES module evaluation when the file contains import, export, or top-level await anywhere in the source. The runnable examples on this page wrap async code in (async () => { ... })() so they also work when pasted into classic-script contexts.

GET with headers

Check res.ok — HTTP error statuses resolve, they don’t throw:
HTTP statuses like 404 or 500 resolve normally. Network failures (DNS, refused connection, too many redirects) reject with strings, and an initial permission denial throws a PermissionDenied error. Always check res.ok or res.status after a response; always handle the permission case separately.

POST JSON

string bodies — and URLSearchParams, which coerces to its query string — reach the wire intact. Everything else is coerced with JS String() semantics: a FormData or Blob arrives as "[object Object]", an ArrayBuffer as "[object ArrayBuffer]", a Uint8Array([104, 105]) as "104,105".
Known issue: fetch does not multipart-encode FormData or send binary bodies as bytes. Build the payload yourself:

Reading the response

Every reader works on Response (and Request). Bodies can be re-read freely (and bodyUsed stays false):

Redirects

Redirects are followed automatically, up to 5 hops. After that fetch throws Too many redirects:
Every hop is re-checked against --allow-net. A redirect that crosses hosts needs both scopes:
A hop outside the scope rejects with the string "PermissionDenied: fetch requires --allow-net". There is no redirect: "manual" mode — the init key is ignored.

HTTPS trust

Public CAs work out of the box. For private/self-signed CAs:
--ca is not accepted by ff start. Use FF_CA_FILE (or FF_CERT) there.
Trust and permission are independent: neither --ca nor FF_CA_FILE grants network access, and --allow-net does not make an untrusted certificate valid. FF_CA_FILE is runtime configuration, so it needs no --allow-env.

Practical example: synced mirror

Fetch a list, then POST each item onward, checking every status:
Both hosts need their own scope; *.example.com would cover neither of these two apex domains.

Reference: limits

Troubleshooting

fetch throws PermissionDenied — the initial URL’s host and port are outside every --allow-net scope. Add the exact target: --allow-net=api.example.com:443. Remember localhost and 127.0.0.1 are different scopes, and HTTPS defaults to port 443. A redirect fails with PermissionDenied: fetch requires --allow-net — a later hop crossed into a host or port you did not grant. Grant every host in the chain, or make the redirect target stay within one host. 404 resolves instead of throwing — by design. Check res.ok / res.status after every call. Lowercase method: "post" arrives as GET — method tokens match exactly; anything unrecognized goes out as GET (the body is still attached). Use "POST". FormData / Blob / Uint8Array body arrives mangled — bodies are string-coerced, not serialized ("[object Object]", "104,105"). Send string, URLSearchParams, or a hand-built multipart string instead. Caught fetch error has no .message — most failures reject with plain strings ("Network error", "Invalid URL", "Too many redirects", and the redirect-hop permission string). Log String(e). The initial permission denial is the exception: it is an Error with .message. Too many redirects — the chain exceeded 5 hops. Inspect res.url on the last good hop or fix the redirect loop server-side. TLS verify fails on a private CA — pass --ca (scripts) or FF_CA_FILE (ff start). Confirm the PEM path is readable. Trust does not replace --allow-net. Hanging with 17+ parallel fetches — the 16-slot pool is full. Await in batches or raise concurrency by sequencing.

See also