{"record":{"id":"67a14bedcaea5c32","repo":"mozilla/pdf.js","slug":"invalid-workersrc-type","errorCode":null,"errorMessage":"Invalid `workerSrc` type.","messagePattern":"Invalid `workerSrc` type\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/worker_options.js","lineNumber":58,"sourceCode":"  }\n\n  /**\n   * @type {string}\n   */\n  static get workerSrc() {\n    return this.#src;\n  }\n\n  /**\n   * @param {string} workerSrc - A string containing the path and filename of\n   *   the worker file.\n   *\n   *   NOTE: The `workerSrc` option should always be set, in order to prevent\n   *         any issues when using the PDF.js library.\n   */\n  static set workerSrc(val) {\n    if (typeof val !== \"string\") {\n      throw new Error(\"Invalid `workerSrc` type.\");\n    }\n    this.#src = val;\n  }\n}\n\nexport { GlobalWorkerOptions };\n","sourceCodeStart":40,"sourceCodeEnd":65,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/worker_options.js#L40-L65","documentation":"Thrown by the GlobalWorkerOptions.workerSrc setter when the value is not a string. workerSrc must be a URL string pointing at the worker script so PDF.js can spawn the worker. Non-string values (URL objects, modules, numbers, undefined) are rejected because they cannot be used to construct a Worker.","triggerScenarios":"GlobalWorkerOptions.workerSrc = <non-string> (e.g. a URL object, a module namespace, undefined).","commonSituations":"Assigning a `new URL(...)` object instead of its .href; importing the worker as a module and assigning the namespace; forgetting to set workerSrc at all in an environment where it is required.","solutions":["Set workerSrc to a string URL of the worker bundle.","If using a URL object, assign url.href (a string).","Use a bundler helper (e.g. Vite's ?worker or Webpack's worker-loader) and pass the resolved string URL."],"exampleFix":"// before\nGlobalWorkerOptions.workerSrc = new URL('pdf.worker.min.mjs', import.meta.url);\n// after\nGlobalWorkerOptions.workerSrc = new URL('pdf.worker.min.mjs', import.meta.url).href;","handlingStrategy":"validation","validationCode":"if (typeof val !== 'string') {\n  throw new Error('workerSrc must be a string URL');\n}\nGlobalWorkerOptions.workerSrc = val;","typeGuard":"function isValidWorkerSrc(val) {\n  return typeof val === 'string' && val.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always set workerSrc to a string URL of the worker bundle.","If you hold a URL object, assign url.href.","Use bundler helpers that resolve to a string URL.","Never assign a module namespace or undefined to workerSrc."],"tags":["worker","configuration","input-validation","api-misuse"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}