{"record":{"id":"64c80ec96719b641","repo":"karatelabs/karate","slug":"dialog-callback-handler-not-supported-on-webdriver-backend","errorCode":null,"errorMessage":"Dialog callback handler not supported on WebDriver backend. Use dialog(true/false) after the dialog appears.","messagePattern":"Dialog callback handler not supported on WebDriver backend\\. Use dialog\\(true/false\\) after the dialog appears\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java","lineNumber":764,"sourceCode":"\n    // ========== Dialog (limited support) ==========\n\n    @Override\n    public Dialog getDialog() {\n        try {\n            String text = session.getAlertText();\n            if (text != null) {\n                return new W3cDialog(session, text);\n            }\n        } catch (Exception e) {\n            // No alert present\n        }\n        return null;\n    }\n\n    @Override\n    public void onDialog(DialogHandler handler) {\n        throw new UnsupportedOperationException(\n                \"Dialog callback handler not supported on WebDriver backend. \"\n                        + \"Use dialog(true/false) after the dialog appears.\");\n    }\n\n    // ========== Navigation (abstract in Driver) ==========\n\n    @Override\n    public void setUrl(String url) {\n        session.navigateTo(url);\n    }\n\n    @Override\n    public void waitForPageLoad(PageLoadStrategy strategy) {\n        // W3C handles page load internally - navigation commands are blocking\n    }\n\n    @Override\n    public void waitForPageLoad(PageLoadStrategy strategy, java.time.Duration timeout) {","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java#L746-L782","documentation":"W3cDriver (WebDriver-based drivers) cannot register an async dialog callback handler, so onDialog(DialogHandler) unconditionally throws UnsupportedOperationException. WebDriver's protocol handles JS dialogs synchronously; the callback style is only available on backends like Chrome DevTools-based drivers. The message directs users to the dialog(true/false) API.","triggerScenarios":"Calling driver.onDialog(handler) — or configuring Karate to set a dialog handler — while using a WebDriver-backed driver (geckodriver, safaridriver, or any W3C protocol driver) instead of a CDP-backed one.","commonSituations":"Code shared between Chrome (CDP) and Firefox (WebDriver) runs onDialog on both; users migrating tests from the CDP driver to a WebDriver backend; copy-pasted setup code enabling dialog auto-handling.","solutions":["Remove the onDialog call and instead call driver.dialog(true) (accept) or driver.dialog(false) (dismiss) after the dialog appears","Use a CDP-backed driver (e.g. chromedriver via DevTools) if callback-style dialog handling is required","Guard the setup with a driver-type check so shared code skips onDialog on WebDriver backends","Avoid triggering native alert/confirm/prompt in WebDriver tests when possible; use in-page dialogs instead"],"exampleFix":"// before\ndriver.onDialog(dialog -> dialog.dismiss()); // throws on WebDriver backend\n// after\n// no onDialog; when a dialog appears:\ndriver.dialog(false); // dismiss it synchronously","handlingStrategy":"fallback","validationCode":"// detect WebDriver backend before using callback API\nboolean isWebDriver = driver instanceof io.karatelabs.driver.w3c.W3cDriver;","typeGuard":"if (driver instanceof io.karatelabs.driver.w3c.W3cDriver) {\n    // WebDriver backend: use dialog(true/false) flow\n} else {\n    driver.onDialog(handler);\n}","tryCatchPattern":"try {\n    driver.onDialog(handler);\n} catch (UnsupportedOperationException e) {\n    // fall back to dialog(true/false) after the dialog appears\n    driver.dialog(false);\n}","preventionTips":["Know which backend (CDP vs WebDriver) each test targets before choosing dialog APIs","Never call onDialog in code shared across drivers without an instanceof guard","Prefer in-page (HTML) dialogs over native alert/confirm for portability"],"tags":["webdriver","unsupported-operation","dialog"],"backgroundTag":"unsupported-operation","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}