{"record":{"id":"75736e81d730740d","repo":"mozilla/pdf.js","slug":"invalid-workerport-type","errorCode":null,"errorMessage":"Invalid `workerPort` type.","messagePattern":"Invalid `workerPort` type\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/worker_options.js","lineNumber":37,"sourceCode":"  static #src = \"\";\n\n  /**\n   * @type {Worker | null}\n   */\n  static get workerPort() {\n    return this.#port;\n  }\n\n  /**\n   * @param {Worker | null} workerPort - Defines global port for worker process.\n   *   Overrides the `workerSrc` option.\n   */\n  static set workerPort(val) {\n    if (\n      !(typeof Worker !== \"undefined\" && val instanceof Worker) &&\n      val !== null\n    ) {\n      throw new Error(\"Invalid `workerPort` type.\");\n    }\n    this.#port = val;\n  }\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   */","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/worker_options.js#L19-L55","documentation":"Thrown by the GlobalWorkerOptions.workerPort setter when the value is not null and not an instance of Worker. The setter accepts only a real Web Worker (or null to clear it) because the port is used directly for message passing. Any other value (a MessagePort, a function, an object) is rejected.","triggerScenarios":"GlobalWorkerOptions.workerPort = <not a Worker and not null> (e.g. a MessagePort, a worker factory, an object literal).","commonSituations":"Confusing Worker with MessagePort; assigning a function that creates a worker instead of the worker instance; passing a worker from a different realm/blob that fails the instanceof check.","solutions":["Pass an actual Worker instance: new Worker(new URL('pdf.worker.min.mjs', import.meta.url), { type: 'module' }).","Pass null to clear the port and let PDF.js spawn its own worker from workerSrc.","Ensure the Worker global is defined in the environment (it is not in pure Node without a shim)."],"exampleFix":"// before\nGlobalWorkerOptions.workerPort = myMessagePort;\n// after\nGlobalWorkerOptions.workerPort = new Worker(new URL('pdf.worker.min.mjs', import.meta.url), { type: 'module' });","handlingStrategy":"validation","validationCode":"if (val !== null && !(typeof Worker !== 'undefined' && val instanceof Worker)) {\n  throw new Error('workerPort must be a Worker instance or null');\n}\nGlobalWorkerOptions.workerPort = val;","typeGuard":"function isValidWorkerPort(val) {\n  return val === null || (typeof Worker !== 'undefined' && val instanceof Worker);\n}","tryCatchPattern":null,"preventionTips":["Pass an actual Worker instance, not a MessagePort or factory function.","Pass null to clear the port and let PDF.js spawn its own worker.","Confirm the Worker global exists in your runtime.","Construct the worker with { type: 'module' } when using an ESM worker."],"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"}