{"record":{"id":"3950cfb550ee2619","repo":"mozilla/pdf.js","slug":"binarydatafactory-not-initialized-see-the-usew","errorCode":null,"errorMessage":"`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter.","messagePattern":"`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/api.js","lineNumber":2917,"sourceCode":"        default:\n          throw new Error(`Got unknown object type ${type}`);\n      }\n    });\n\n    messageHandler.on(\"DocProgress\", data => {\n      if (this.destroyed) {\n        return; // Ignore any pending requests if the worker was terminated.\n      }\n      this.#onProgress(data);\n    });\n\n    if (typeof PDFJSDev === \"undefined\" || !PDFJSDev.test(\"MOZCENTRAL\")) {\n      messageHandler.on(\"FetchBinaryData\", async data => {\n        if (this.destroyed) {\n          throw new Error(\"Worker was destroyed.\");\n        }\n        if (!this.binaryDataFactory) {\n          throw new Error(\n            \"`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter.\"\n          );\n        }\n        return this.binaryDataFactory.fetch(data);\n      });\n    }\n  }\n\n  getData() {\n    return this.messageHandler.sendWithPromise(\"GetData\", null);\n  }\n\n  saveDocument() {\n    if (this.annotationStorage.size <= 0) {\n      warn(\n        \"saveDocument called while `annotationStorage` is empty, \" +\n          \"please use the getData-method instead.\"\n      );","sourceCodeStart":2899,"sourceCodeEnd":2935,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/api.js#L2899-L2935","documentation":"A generic Error in the FetchBinaryData handler: the worker requested binary data via the main thread, but transportFactory.binaryDataFactory is null. binaryDataFactory is null when useWorkerFetch is true (MozCentral, or the generic build when all of cMapUrl, standardFontDataUrl, wasmUrl etc. are valid fetch URLs), because under useWorkerFetch the worker fetches directly and the main-thread factory is intentionally not built. Reaching this handler means the configuration diverged: useWorkerFetch said 'no main-thread factory' yet the worker still routed a fetch to main.","triggerScenarios":"A build/config where useWorkerFetch resolved true (so binaryDataFactory is null) but the worker still sent FetchBinaryData to the main thread; custom WorkerTransport setups that override useWorkerFetch incorrectly; partial factory configuration where only some URLs are valid.","commonSituations":"Misconfigured cMapUrl/standardFontDataUrl/wasmUrl; embedding pdf.js with a custom transport that doesn't wire up the factory; version mismatches between worker and API.","solutions":["Ensure pdf.js worker and API builds are the same version (mismatched versions can route messages the wrong way).","If you need main-thread binary fetching, set useWorkerFetch:false and provide cMapUrl/standardFontDataUrl/wasmUrl plus a binaryDataFactory.","Provide all required URLs (cMapUrl, cMapPacked, standardFontDataUrl, wasmUrl) consistently so useWorkerFetch resolves the same way on both sides."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Keep useWorkerFetch consistent with the URLs you provide.\nconst hasAllUrls = src.cMapUrl && src.standardFontDataUrl && src.wasmUrl;\nif (!hasAllUrls && src.useWorkerFetch) {\n  src.useWorkerFetch = false; // let pdf.js build the main-thread factory\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use matching worker and API build versions so message routing agrees.","Provide cMapUrl, standardFontDataUrl, and wasmUrl consistently, or set useWorkerFetch:false.","Avoid overriding useWorkerFetch without also configuring a binaryDataFactory."],"tags":["configuration","fetch","worker","binary-data","useworkerfetch"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}