mozilla/pdf.js · error · Error
response.statusText
Error message
response.statusText
What it means
Thrown by fetchData(url, type) when a fetch() call resolves with response.ok === false. The thrown value is response.statusText — the HTTP reason phrase such as 'Not Found' or 'Forbidden'. fetchData is used internally to load CMaps, standard fonts, and other side resources via DOMBinaryDataFactory, and by direct callers fetching arbitrary PDF resources.
Source
Thrown at src/display/display_utils.js:43
import { PageViewport } from "./page_viewport.js";
import { XfaLayer } from "./xfa_layer.js";
class PixelsPerInch {
static CSS = 96.0;
static PDF = 72.0;
static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
}
async function fetchData(url, type = "text") {
if (
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
isValidFetchUrl(url, document.baseURI)
) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(response.statusText);
}
switch (type) {
case "blob":
return response.blob();
case "bytes":
return response.bytes();
case "json":
return response.json();
}
return response.text();
}
// The Fetch API is not supported.
return new Promise((resolve, reject) => {
const request = new XMLHttpRequest();
request.open("GET", url, /* async = */ true);
request.responseType = type === "bytes" ? "arraybuffer" : type;
View on GitHub (pinned to 5903d58d58)
Solutions
- Open the failing URL directly and fix the server config (serve the folder, return 200).
- Confirm cMapUrl / standardFontDataUrl / wasmUrl paths match the installed pdfjs-dist version.
- If the error is intermittent (5xx), wrap fetchData consumers in retry logic.
Example fix
// before
getDocument({ data, cMapUrl: '/wrong-path/' });
// after
getDocument({ data, cMapUrl: '/assets/pdfjs-4.x/cmaps/' });
// verify: curl -I /assets/pdfjs-4.x/cmaps/GBK-EUC-H.bcmap returns 200 Defensive patterns
Strategy: try-catch
Validate before calling
async function fetchOk(url, type) {
const res = await fetch(url);
if (!res.ok) throw new Error(`${url} -> HTTP ${res.status} ${res.statusText}`);
return type === 'bytes' ? res.bytes() : res.text();
} Type guard
null
Try / catch
try {
await fetchData(url, 'bytes');
} catch (e) {
if (/^(Bad Request|Not Found|Forbidden|Internal Server Error)$/.test(e.message)) {
// surface as a config/hosting problem
} else throw e;
} Prevention
- Verify each asset URL with curl -I before integrating.
- Serve assets same-origin when possible.
- Log the URL alongside the statusText for triage.
When it happens
Trigger: A 404/403/500 on a CMap, standard-font, or other side resource URL; the server returning a non-2xx status for any URL passed to fetchData; misconfigured cMapUrl/standardFontDataUrl pointing at a path the server does not serve.
Common situations: Self-hosted assets missing after a deploy; reverse proxy returning 404 for the /cmaps path; auth-gated CDN returning 403; version skew between pdfjs-dist and the asset folders.
Related errors
- Unable to load ${this.#errorStr[kind]} data at: ${url}
- Invalid factory url: "${val}" must include trailing slash.
- Ensure that the `${kind}` API parameter is provided.
- cmap files were not found
- Bad begin offset: ${begin}
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/53ac3993cdbb3135.
Report an issue: GitHub.