{"record":{"id":"3085958d1edda3f4","repo":"mozilla/pdf.js","slug":"failed-to-fetch-file-url-with-response-sta","errorCode":null,"errorMessage":"Failed to fetch file \"${url}\" with \"${response.statusText}\".","messagePattern":"Failed to fetch file \"(.+?)\" with \"(.+?)\"\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/core_utils.js","lineNumber":127,"sourceCode":"  }\n  let dataLength = 0;\n  for (let i = 0; i < length; i++) {\n    dataLength += arr[i].byteLength;\n  }\n  const data = new Uint8Array(dataLength);\n  let pos = 0;\n  for (let i = 0; i < length; i++) {\n    const item = new Uint8Array(arr[i]);\n    data.set(item, pos);\n    pos += item.byteLength;\n  }\n  return data;\n}\n\nasync function fetchBinaryData(url) {\n  const response = await fetch(url);\n  if (!response.ok) {\n    throw new Error(\n      `Failed to fetch file \"${url}\" with \"${response.statusText}\".`\n    );\n  }\n  return response.bytes();\n}\n\n/**\n * Get the value of an inheritable property.\n *\n * If the PDF specification explicitly lists a property in a dictionary as\n * inheritable, then the value of the property may be present in the dictionary\n * itself or in one or more parents of the dictionary.\n *\n * If the key is not found in the tree, `undefined` is returned. Otherwise,\n * the value for the key is returned or, if `stopWhenFound` is `false`, a list\n * of values is returned.\n *\n * @param {Dict} dict - Dictionary from where to start the traversal.","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/core_utils.js#L109-L145","documentation":"Thrown by fetchBinaryData when the HTTP fetch resolves with response.ok === false. The helper is used internally to load .bcmap CMap files and standard-font metric files; the error message includes the URL and statusText so the missing asset is identifiable. It is a wrapper around the browser fetch() that turns non-2xx responses into exceptions.","triggerScenarios":"getDocument configured with cMapUrl or standardFontDataUrl pointing at a path that returns 4xx/5xx (404 is most common); CORS preflight rejection; the asset server is down or returns an error status.","commonSituations":"Deployments that copy pdf.js/pdf.worker.js but forget to ship the cmaps/ and standard_fonts/ directories from pdfjs-dist; a wrong or missing trailing slash in cMapUrl; CORS blocking cross-origin asset fetches from the worker.","solutions":["Ship cmaps/ and standard_fonts/ from pdfjs-dist and set cMapUrl/standardFontDataUrl to their absolute, correctly-slash-terminated paths.","Verify each URL returns 200 in a browser devtools network panel (watch for 404 or CORS errors).","Serve the assets with permissive CORS headers if the worker origin differs from the asset origin.","If assets cannot be hosted at a URL, provide a custom fetchBuiltInCMap / standard-font loader that resolves them from local bytes."],"exampleFix":"// before\ngetDocument({ url, cMapUrl: '/cmaps' }); // no trailing slash, packed unset\n\n// after\ngetDocument({\n  url,\n  cMapUrl: '/assets/cmaps/',\n  cMapPacked: true,\n  standardFontDataUrl: '/assets/standard_fonts/',\n});","handlingStrategy":"try-catch","validationCode":"// Probe asset URLs at app startup so a missing CMap/font fails fast and visibly\nasync function assertAssetOk(url) {\n  const res = await fetch(url, { method: 'HEAD' });\n  if (!res.ok) throw new Error(`Missing pdf.js asset: ${url} (${res.status})`);\n}\nawait assertAssetOk(`${cMapUrl}78-RKSJ-H.bcmap`);","typeGuard":null,"tryCatchPattern":"try {\n  await loadingTask.promise;\n} catch (e) {\n  if (/Failed to fetch file/.test(e.message)) {\n    console.error('CMap/standard-font asset unreachable - check cMapUrl/standardFontDataUrl/CORS', e);\n  } else throw e;\n}","preventionTips":["Always ship cmaps/ and standard_fonts/ from pdfjs-dist alongside the worker.","Set cMapUrl and standardFontDataUrl to absolute, slash-terminated paths.","Verify each asset URL returns 200 and permissive CORS headers in DevTools.","Add a CI smoke test that loads a CJK + standard-font PDF against your deployment.","For offline/node usage, provide a custom fetchBuiltInCMap that reads local files."],"tags":["network","cmap","font","configuration","deployment","cors"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}