fetch Rejected on file://, Search Becomes a Script
A fetch for a neighboring JSON file fails under file:// because local origins are opaque. The search index ships as a script file and IndexedDB stores it.
TL;DR
Browsers treat local files as opaque origins, so fetch can't load a JSON file opened via file://. The fix ships the search index as a JavaScript file assigning a global, loads it with a script tag, and caches it in IndexedDB, re-seeding when a captured_at version changes. A build audit also fails if any screenshot lacks a caption.
The plan for KotaPortal's documentation app had a search feature that looked simple when I wrote it: read search.json with fetch, render the results. The file sits in the same folder as index.html, no server, no different domain. Opened through file://, the browser refused the request before the first query ever ran. The message is short: CORS request not HTTP [4].
My initial assumption: files in the same folder count as one origin, so fetch should just work. The design had already locked JSON as the data source. The assumption was wrong, and the refusal is not a browser bug, it is deliberate policy.
Local file origins are opaque by design
Modern browsers such as Firefox and Chrome treat all local files as opaque origins. The change aligns with the URL specification's recommendation to treat file origins as opaque when in doubt, and MDN documents the security motivation through advisory CVE-2019-11730 [4]. The direct consequence hits fetch: CORS requests may only use the HTTP or HTTPS scheme, and file:/// is neither. Even a fetch targeting a file in its own folder gets rejected.
Two things still work under file://: script tags and IndexedDB. This was verified before the design was locked, because only two realistic options remained: run a permanent local server just to open documentation, or change how data arrives. The app is opened straight from a folder by non-developer staff, so a local server was not a practical requirement to add.
Search data becomes a script file
The way out: the search index is not shipped as JSON but as a plain JavaScript file named search-data.js that assigns the global window.MANUAL_DOCS. A script tag does not go through fetch, so the opaque-origin rule never touches it. Once loaded, the data is in memory: group names, admin URLs, public URLs, the list of captioned steps, and each group's capacity notes.
IndexedDB takes the storage role. It can be opened from file:// and offers query-oriented persistence without a network dependency [5]. On the first visit, the contents of window.MANUAL_DOCS are copied into an object store named docs, keyed by group. Queries split the input into tokens, match across all fields, rank group-name matches first, and every result links to that group's page.
localStorage was rejected for a structural reason: it only stores strings with no query shape, while cross-field matching needs the records laid out for it. Because the storage is bound to the file origin, the copy created on the first visit keeps serving later visits with no extra work.
Versioning and the re-seed hook
Documentation changes over time, so the app needs to know when its local copy is stale. The hook ships with the API: indexedDB.open takes a version number, and raising it fires onupgradeneeded so the handler can update the structure [5]. The app uses the same mechanism with its own version marker. Every regeneration carries a captured_at field in the manifest; when the value stored in IndexedDB differs from the one the script brings, the whole store is re-seeded. One field, one decision, no extra synchronization logic.
Two fields for honesty
The second lesson lives in the content contract. The manifest carries two representations of every screenshot: the screenshots field is the raw file list used by the build audit, and the steps field pairs each shot with its caption for readers. The audit step asserts it plainly: a screenshot without a caption fails the build.
The split is not redundancy. The first field answers the machine's question, whether the promised files actually exist. The second answers the human question, what the image proves. Honesty is encoded into the data contract: an incomplete documentation set can never finish building, because the build refuses to pass.
The same contract shapes each group page: a header with the group name and admin URL, the captioned step pairs, then the public-frontend section explained last. Groups without a public surface get an honest note about that state, not an empty section pretending otherwise. Capacity labels follow product truth, not aspiration.