{"record":{"id":"4624a26ffee468a4","repo":"mozilla/pdf.js","slug":"the-overlay-is-already-active","errorCode":null,"errorMessage":"The overlay is already active.","messagePattern":"The overlay is already active\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"web/overlay_manager.js","lineNumber":57,"sourceCode":"\n    dialog.addEventListener(\"cancel\", ({ target }) => {\n      if (this.#active === target) {\n        this.#active = null;\n      }\n    });\n  }\n\n  /**\n   * @param {HTMLDialogElement} dialog - The overlay's DOM element.\n   * @returns {Promise} A promise that is resolved when the overlay has been\n   *                    opened.\n   */\n  async open(dialog) {\n    if (!this.#overlays.has(dialog)) {\n      throw new Error(\"The overlay does not exist.\");\n    } else if (this.#active) {\n      if (this.#active === dialog) {\n        throw new Error(\"The overlay is already active.\");\n      } else if (this.#overlays.get(dialog).canForceClose) {\n        await this.close();\n      } else {\n        throw new Error(\"Another overlay is currently active.\");\n      }\n    }\n    this.#active = dialog;\n    dialog.showModal();\n  }\n\n  /**\n   * @param {HTMLDialogElement} dialog - The overlay's DOM element.\n   * @returns {Promise} A promise that is resolved when the overlay has been\n   *                    closed.\n   */\n  async close(dialog = this.#active) {\n    if (!this.#overlays.has(dialog)) {\n      throw new Error(\"The overlay does not exist.\");","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/web/overlay_manager.js#L39-L75","documentation":"Thrown by OverlayManager.open when the requested dialog is already the active overlay (this.#active === dialog). The manager only allows one active modal at a time, so reopening the currently-shown dialog is rejected.","triggerScenarios":"Calling open(dialog) on the same element that is currently set as #active (already shown via showModal). Often a double-open race or a UI button that re-triggers open.","commonSituations":"User double-clicks a button that opens an already-open dialog, or an event handler fires twice without dedup.","solutions":["Guard with OverlayManager.active before opening: if (OverlayManager.active !== dialog) await open(dialog).","Debounce or disable the triggering control while the dialog is shown.","Use closeIfActive to tear down before reopening."],"exampleFix":"// before\nawait OverlayManager.open(dialog); // throws if already open\n\n// after\nif (OverlayManager.active !== dialog) {\n  await OverlayManager.open(dialog);\n}","handlingStrategy":"validation","validationCode":"if (OverlayManager.active !== dialog) {\n  await OverlayManager.open(dialog);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await OverlayManager.open(dialog);\n} catch (e) {\n  if (e.message === 'The overlay is already active.') return;\n  throw e;\n}","preventionTips":["Check OverlayManager.active before opening.","Disable the trigger control while the dialog is shown.","Deduplicate rapid open events."],"tags":["overlay","state","duplicate","ui-utils"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}