playwright: [BUG] page.on('dialog', ()=>{}) doesn't work when external URL handlers are opened. e.g. Telegram

Context:

  • Playwright Version: 1.17.1
  • Operating System: macOS 12.0.1
  • Node.js version: v17.0.1
  • Browser: Chromium
  • Extra:
const { chromium } = require('playwright');

(async () => {
  // const browser = await chromium.connectOverCDP('@todo:wsUrl');
  // const context = browser.contexts()[0];

  const context = await chromium.launch({ headless: false });

  const page = await context.newPage();
  page.on('dialog', async (dialog) => {
    console.log('dialog1', dialog.message());
    await dialog.dismiss();
  });
  await page.goto('https://t.me/wallstreetbets');
  page.on('dialog', async (dialog) => {
    console.log('dialog2', dialog.message());
    await dialog.dismiss();
  });
})();

Describe the bug Dialog still exists, and the two logs are not printed.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 26
  • Comments: 31 (4 by maintainers)

Most upvoted comments

Is this a feature yet? Also hit the issue. Playwright can see the alert in the shadow dom as interactable, but will not accept the alert as a dialog and accept it.

@dgozman possible, you can avoid opening this type of dialog, by adding those two lines to your Dockerfile:

# to avoid a confirmation dialog for opening external URLs
RUN mkdir -p /etc/chromium/policies/managed  
RUN echo '{ "URLBlocklist": [ "<your_url_app>:*" ] }' > /etc/chromium/policies/managed/blocklist.json

in my case <your_url_app> = msteams

+1 for this bug. I recently hit this. (I think.)

I am doing this in my Javascript application code that’s run in the browser. On a mobile device in a real app, it would open the app that’s registered to handle the scheme.

document.location.href = "customscheme://whatever"

Out of the box, tests for this don’t work. This times out.

await page.waitForURL("customscheme://whatever")

I thought that I could stub it:

await page.route("customscheme://whatever", route => route.fulfill({status: 200, body: "ok"}))
await page.waitForURL("customscheme://whatever")

Stubbing does not seem to have any effect, still times out.

I wish there was a way to assert with Playwright that “navigation” to a custom URL scheme happens.

This is a confirmation dialog for opening external url handler. These dialogs are not currently instrumented in Chromium and not exposed by Playwright in any form. Looking at the Chromium code starting from the url loader I don’t see any flags that would disable the external schemes altogether. Looks like in other browsers we do disable it as I don’t see the dialog there. Leaving this issue open as a feature request.

This is how I solved my problem. Notice that I needed to create the “Chromium” key and added both URL Blocklist and URLAllowlist. image image