jackwener/OpenCLI · error

This browser session does not support JavaScript dialog hand

Error message

This browser session does not support JavaScript dialog handling

What it means

The `browser dialog accept` command requires `page.handleJavaScriptDialog`; the active browser session does not expose dialog handling, so the command throws this capability error. Native dialog interception needs protocol-level support not present in every backend.

Source

Thrown at src/cli.ts:2361

    }));

  addBrowserTabOption(browser.command('keys').argument('<key>', 'Key to press (Enter, Escape, Tab, Control+a)'))
    .description('Press keyboard key')
    .action(browserAction(async (page, key) => {
      await page.pressKey(key);
      console.log(`Pressed: ${key}`);
    }));

  const browserDialog = browser
    .command('dialog')
    .description('Handle a blocking JavaScript alert/confirm/prompt dialog');

  addBrowserTabOption(browserDialog.command('accept')
    .option('--text <text>', 'Prompt text to submit for prompt() dialogs')
    .description('Accept the currently open JavaScript dialog'))
    .action(browserAction(async (page, opts?: { text?: string }) => {
      if (!page.handleJavaScriptDialog) {
        throw new Error('This browser session does not support JavaScript dialog handling');
      }
      try {
        await page.handleJavaScriptDialog(true, opts?.text);
      } catch (err) {
        const message = getErrorMessage(err);
        if (message.toLowerCase().includes('no dialog')) {
          console.log(JSON.stringify({
            error: {
              code: 'no_javascript_dialog',
              message: 'No JavaScript dialog is currently open.',
            },
          }, null, 2));
          process.exitCode = EXIT_CODES.USAGE_ERROR;
          return;
        }
        throw err;
      }
      console.log(JSON.stringify({ handled: true, action: 'accept', ...(opts?.text !== undefined && { text: opts.text }) }, null, 2));

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use a backend that supports dialog handling (Playwright/Puppeteer-based).
  2. Configure the driver to auto-accept dialogs if manual handling is unsupported.
  3. Avoid triggering dialogs (alert/confirm/prompt) in the page under test, or stub them via `browser eval` overriding window.alert/confirm/prompt.

Example fix

// before
browser --backend minimal dialog accept --text yes
// after
browser --backend playwright dialog accept --text yes
Defensive patterns

Strategy: type-guard

Validate before calling

const page = await getBrowserPage();
if (typeof page.handleJavaScriptDialog !== 'function') {
  throw new Error('Session cannot handle dialogs; use a dialog-capable backend');
}

Type guard

function supportsDialogs(page) {
  return typeof page?.handleJavaScriptDialog === 'function';
}

Try / catch

try {
  await run(['browser', 'dialog', 'accept']);
} catch (err) {
  if (String(err.message).includes('does not support JavaScript dialog handling')) {
    await run(['browser', 'eval', "window.confirm=()=>true; window.prompt=()=>'yes'; window.alert=()=>{}"]);
  } else throw err;
}

Prevention

When it happens

Trigger: Running `browser dialog accept` (with optional `--text`) on a session whose page object lacks `handleJavaScriptDialog`.

Common situations: Backends without dialog auto-handling hooks (no Page.javascriptDialogOpening-style support); remote or restricted sessions where dialogs are auto-dismissed by the driver.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/8c13c05194c61aea. Report an issue: GitHub.