{"record":{"id":"c2073ac3e2eb9ba3","repo":"SeleniumHQ/selenium","slug":"message","errorCode":null,"errorMessage":"${message}","messagePattern":"\\$\\{message\\}","errorType":"exception","errorClass":"UnexpectedAlertOpenError","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/lib/error.js","lineNumber":560,"sourceCode":"  // Handle the legacy Selenium error response format.\n  if (isObject(responseObj) && typeof responseObj.status === 'number' && responseObj.status !== 0) {\n    const { status, value } = responseObj\n\n    let ctor = LEGACY_ERROR_CODE_TO_TYPE.get(status) || WebDriverError\n\n    if (!value || typeof value !== 'object') {\n      throw new ctor(value + '')\n    } else {\n      let message = value['message'] + ''\n      if (ctor !== UnexpectedAlertOpenError) {\n        throw new ctor(message)\n      }\n\n      let text = ''\n      if (value['alert'] && typeof value['alert']['text'] === 'string') {\n        text = value['alert']['text']\n      }\n      throw new UnexpectedAlertOpenError(message, text)\n    }\n  }\n  return responseObj\n}\n\n// PUBLIC API\n\nmodule.exports = {\n  ErrorCode,\n\n  WebDriverError,\n  DetachedShadowRootError,\n  ElementClickInterceptedError,\n  ElementNotInteractableError,\n  ElementNotSelectableError,\n  InsecureCertificateError,\n  InvalidArgumentError,\n  InvalidCookieDomainError,","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/lib/error.js#L542-L578","documentation":"Thrown by checkLegacyResponse() in error.js when a legacy Selenium 2.0 wire protocol response has a non-zero numeric `status` and the `value` is an object containing a `message`. The error constructor is resolved from LEGACY_ERROR_CODE_TO_TYPE; for UnexpectedAlertOpenError it also extracts the alert text. The message comes from value.message.","triggerScenarios":"Connecting to a legacy Selenium 2 server/endpoint that returns {status, value:{message,...}} format. An unexpected JavaScript alert is open when a command executes, and the server uses the legacy protocol. A third-party service using the legacy wire protocol returns an error.","commonSituations":"Using old Selenium server/Grid versions (pre-W3C); third-party testing services with legacy protocol support; tests that trigger unexpected browser alerts; mixed protocol environments.","solutions":["Upgrade to a W3C-compliant Selenium server/Grid (Selenium 3.141+ in W3C mode or Selenium 4+).","Handle unexpected alerts proactively using the Alert API: driver.switchTo().alert().dismiss().","Read value.message and value.alert.text in the caught error for root-cause diagnosis.","Set pageLoadStrategy or unexpectedAlertBehavior capability to control alert handling."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  // ... execute command ...\n} catch (e) {\n  if (e instanceof UnexpectedAlertOpenError) {\n    console.warn('Unexpected alert:', e.text || '(no text)')\n    await driver.switchTo().alert().dismiss()\n    // retry the command if appropriate\n  }\n  throw e\n}","preventionTips":["Upgrade to a W3C-compliant Selenium server (Selenium 4+) to avoid legacy protocol responses.","Set the unexpectedAlertBehavior capability ('accept', 'dismiss', or 'ignore') to control alert handling.","Use driver.switchTo().alert() to handle expected alerts before they block commands.","Watch for the UnexpectedAlertOpenError type specifically and extract alert text for diagnosis."],"tags":["error-handling","legacy","protocol","alert","webdriver"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}