mozilla/pdf.js · error · Error
Invalid factory url: "${val}" must include trailing slash.
Error message
Invalid factory url: "${val}" must include trailing slash. What it means
Thrown by getFactoryUrlProp when a configured cMapUrl, standardFontDataUrl, or wasmUrl is a string that does not end with '/'. PDF.js builds resource URLs via simple concatenation (baseUrl + filename), so a missing trailing slash produces paths like 'https://x/cmaps' + 'JP' rather than 'https://x/cmaps/JP', silently breaking CJK/font/WASM fetching. The check makes this a hard error instead.
Source
Thrown at src/display/api_utils.js:98
ArrayBuffer.isView(val) ||
(typeof val === "object" && !isNaN(val?.length))
) {
return new Uint8Array(val);
}
throw new Error(
"Invalid PDF binary data: either TypedArray, " +
"string, or array-like object is expected in the data property."
);
}
function getFactoryUrlProp(val) {
if (typeof val !== "string") {
return null;
}
if (val.endsWith("/")) {
return val;
}
throw new Error(`Invalid factory url: "${val}" must include trailing slash.`);
}
const isRefProxy = v =>
typeof v === "object" &&
Number.isInteger(v?.num) &&
v.num >= 0 &&
Number.isInteger(v?.gen) &&
v.gen >= 0;
const isNameProxy = v => typeof v === "object" && typeof v?.name === "string";
const isValidExplicitDest = _isValidExplicitDest.bind(
null,
/* validRef = */ isRefProxy,
/* validName = */ isNameProxy
);
class LoopbackPort {View on GitHub (pinned to 5903d58d58)
Solutions
- Append '/' to the configured URL: cMapUrl: 'https://cdn.example.com/cmaps/'.
- Normalize at config time: const withSlash = url.endsWith('/') ? url : url + '/'.
- Verify the same for standardFontDataUrl and wasmUrl when used.
Example fix
// before
getDocument({ data, cMapUrl: 'https://cdn.example.com/cmaps' });
// after
getDocument({ data, cMapUrl: 'https://cdn.example.com/cmaps/' }); Defensive patterns
Strategy: validation
Validate before calling
function ensureTrailingSlash(u) {
return typeof u === 'string' && !u.endsWith('/') ? u + '/' : u;
}
getDocument({
data,
cMapUrl: ensureTrailingSlash(config.cMapUrl),
standardFontDataUrl: ensureTrailingSlash(config.standardFontDataUrl),
}); Type guard
null
Try / catch
null
Prevention
- Normalize every factory URL with a trailing slash at config build time.
- Keep config in one place so the rule is applied uniformly.
- Add a CI check that asserts these URLs end with '/'.
When it happens
Trigger: Passing getDocument({ cMapUrl: 'https://cdn.example/cmaps' }), or any of the three factory URLs without the closing slash.
Common situations: Copy-pasting a base URL from a hosting panel that strips trailing slashes; switching from a version of pdfjs that auto-appended '/' to one that does not; CDN config that canonicalizes URLs without slashes.
Related errors
- Ensure that the `${kind}` API parameter is provided.
- Unable to load ${this.#errorStr[kind]} data at: ${url}
- response.statusText
- cmap files were not found
- No ICC color space support
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/d44150d472223bd2.
Report an issue: GitHub.