playwright icon indicating copy to clipboard operation
playwright copied to clipboard

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

Open lokiikoll opened this issue 3 years ago • 21 comments

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.

lokiikoll avatar Dec 18 '21 23:12 lokiikoll

@heijingg I don't see any dialogs on 'https://t.me/wallstreetbets'. Are you sure those are dialogs (alert/confirm/prompt), and not some web content?

dgozman avatar Dec 20 '21 20:12 dgozman

@heijingg I don't see any dialogs on 'https://t.me/wallstreetbets'. Are you sure those are dialogs (alert/confirm/prompt), and not some web content?

image

I don't know how to use code to detect whether this is a Dialog, but it can cover my debug window and bookmarks. I believe this can only be done by Dialog.

lokiikoll avatar Dec 21 '21 13:12 lokiikoll

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.

yury-s avatar Dec 21 '21 23:12 yury-s

How it's possible to handle this type of dialog in Playwright? Have the same issue with teams links : image

DarynaGrytsai avatar Aug 03 '22 10:08 DarynaGrytsai

@DarynaGrytsai This is not possible today.

dgozman avatar Aug 03 '22 16:08 dgozman

@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

DarynaGrytsai avatar Aug 05 '22 14:08 DarynaGrytsai

/etc/chromium/policies/managed/

these lines worked for me:

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

civan avatar Sep 08 '22 01:09 civan

Is this still open as a feature request?

We're migrating from Protractor to Playwright and the protocol handler pop up is causing us headaches. In Protractor we were able to supply protocol_handler in prefs in ChromeOptions and set it to true/false, however that doesn't look like an option in Playwright

Edit: We got round it by using launchPersistentContext. We had to accept the protocol handler and check the "always allow..." box manually the first time but then all subsequent runs didn't encounter the pop up.

Playwrighting avatar Jan 12 '23 14:01 Playwrighting

Yes it seems. We can overcome handling this issue by adding URLAllowlist in Registry Editor. image

EdmaMahesh avatar Jan 25 '23 11:01 EdmaMahesh

Hi, Is there any fix in place for this bug in Playwright at the moment? I have come across the same kind of issue and need a resolution that can work on all browsers or machines if a page is trying to open an external application. Does anyone have any ideas about this on how to interact with an external permission prompt?

Tash2610 avatar Feb 24 '23 08:02 Tash2610

Hi @Tash2610 , We can bypass the appearing of external window. Please refer my comment to resolve the issue by adding it in Registry Editor

EdmaMahesh avatar Feb 24 '23 08:02 EdmaMahesh

Hi @Tash2610 , We can bypass the appearing of external window. Please refer my comment to resolve the issue by adding it in Registry Editor

Hi @EdmaMahesh, We don't want to bypass external window but need to validate the text on it. Is there a way to do that? Also, to bypass we need to add such URL in the registry editor of the machine where we are executing but can we bypass through registry during CI/CD execution as well?

Tash2610 avatar Feb 24 '23 09:02 Tash2610

I haven't have any solution at the moment to validate the text on it. To bypass in CI/CD yes. We need to run in headless mode(It doesn't require adding details in Registry)

EdmaMahesh avatar Feb 24 '23 09:02 EdmaMahesh

+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.

jaanus avatar Sep 07 '23 07:09 jaanus

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

Selenium-ToolBox avatar Oct 23 '23 19:10 Selenium-ToolBox

the same staff for me

rmarinsky avatar Dec 29 '23 21:12 rmarinsky

Having the same issue there.. I'd like my main browser to keep working as is today as some apps like Loom login depend on the external protocol handlers. I'd like my test browser to reject any external protocol handler. Ideally this would have been supported by the arguments passed to Chromium, but I can't find any such toggles 😞

dinamic avatar Mar 19 '24 18:03 dinamic