playwright
playwright copied to clipboard
[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.
@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?
@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?
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.
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.
How it's possible to handle this type of dialog in Playwright? Have the same issue with teams links :
@DarynaGrytsai This is not possible today.
@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
/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
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.
Yes it seems. We can overcome handling this issue by adding URLAllowlist in Registry Editor.
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?
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 @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?
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)
+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 how I solved my problem. Notice that I needed to create the "Chromium" key and added both URL Blocklist and URLAllowlist.
the same staff for me
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 😞