{"record":{"id":"3e51fd1c75979f62","repo":"karatelabs/karate","slug":"dialog-handler-did-not-resolve-dialog-auto-dismissing","errorCode":null,"errorMessage":"dialog handler did not resolve dialog, auto-dismissing","messagePattern":"dialog handler did not resolve dialog, auto-dismissing","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java","lineNumber":950,"sourceCode":"                    dialogHandler.handle(dialog);\n                } catch (Exception e) {\n                    // A handler that calls accept()/dismiss() can lose a race with the\n                    // dialog already being gone — auto-dismissed, or resolved by another\n                    // event on the cdp-event thread — for which CDP returns \"No dialog is\n                    // showing\" (-32602). That is benign (the dialog IS resolved, just not\n                    // by this call), so don't surface it at ERROR; only genuine handler\n                    // failures should be loud.\n                    String msg = e.getMessage();\n                    if (msg != null && msg.contains(\"No dialog is showing\")) {\n                        logger.debug(\"dialog handler: dialog already resolved (benign race): {}\", msg);\n                    } else {\n                        logger.error(\"dialog handler error: {}\", msg);\n                    }\n                }\n                // If handler didn't resolve the dialog, auto-dismiss\n                // Use local 'dialog' reference, not 'currentDialog' which may be null due to race\n                if (!dialog.isHandled()) {\n                    logger.warn(\"dialog handler did not resolve dialog, auto-dismissing\");\n                    try {\n                        dialog.dismiss();\n                    } catch (Exception e) {\n                        // Dialog may already be gone due to race with another event handler\n                        logger.trace(\"auto-dismiss failed (dialog likely already handled): {}\", e.getMessage());\n                    }\n                }\n                // Clear after handling\n                currentDialog = null;\n                currentDialogText = null;\n            }\n            if (dialogHandler == null) {\n                // A beforeunload prompt (\"Leave page?\") with no handler registered is\n                // always auto-confirmed: it only ever fires on an unload/navigation, so\n                // \"proceed\" is the only sane default. We must NOT gate this on\n                // pendingNavigationUrl — that flag is cleared as soon as setUrl returns,\n                // and for data:/about: navigations setUrl returns synchronously (no\n                // page-load wait), so the gate can already be null by the time the","sourceCodeStart":932,"sourceCodeEnd":968,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java#L932-L968","documentation":"When a JS dialog (alert/confirm/prompt) fires, CdpDriver invokes any user-registered dialog handler. If after the handler runs the dialog is still unhandled, the driver logs this warning and auto-dismisses it so the page cannot stay blocked. A final failure to dismiss is traced only, since a race may have resolved it already.","triggerScenarios":"A page under test opens alert()/confirm()/beforeunload dialogs and either no dialog handler is registered or the registered handler does not call accept()/dismiss() before returning.","commonSituations":"beforeunload prompts appearing during navigation teardown; test forgot to mock/accept an expected alert; handler threw an error (logged via 'dialog handler error') leaving the dialog open.","solutions":["Register a dialog handler (dialog.handle(dialog -> dialog.accept()) or dismiss) in the feature/script so Karate does not auto-dismiss","Ensure the handler always calls accept() or dismiss() on every branch, including error paths","If the dialog is unexpected, fix the page or suppress dialogs in test mode","If auto-dismiss races and hangs, update Karate — newer versions bound the dismiss"],"exampleFix":"// before\n// no dialog handler registered; alert blocks scenario\n// after\ndriver.handleDialog(dialog -> dialog.accept());","handlingStrategy":"try-catch","validationCode":"// declare dialog policy up front in test setup\ndriver.handleDialog(dialog -> dialog.accept());","typeGuard":null,"tryCatchPattern":"try { scenario.actionThatMayAlert(); } catch (Exception e) {\n    // dialog was auto-dismissed; assert state accordingly\n}","preventionTips":["Always register a dialog handler when the page can open dialogs","Ensure handlers call accept() or dismiss() on all branches","Suppress beforeunload prompts in test builds of the page","Watch for 'dialog handler error' logs — a throwing handler leaves dialogs for auto-dismiss"],"tags":["cdp","dialog","auto-dismiss","page-interaction"],"backgroundTag":"unexpected-response-shape","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"}