-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] ClickAsync() on popup window that closes itself causes exception #26900
Comments
Can you share a reproducible which demonstrates the issue with actual and expected behavior? |
unfortunately it's with a financial website that requires an account and login. my code is very basic and the relevant part is above. is there some other way to provide you with any additional info you need to address the issue? btw- thanks for your hard work, the project is fantastic. |
additional info: |
Thanks for filing! I can reproduce actually with this code which passes in CR and WK but fails in FF: using Microsoft.Playwright;
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Webkit.LaunchAsync(new BrowserTypeLaunchOptions() { Headless = false });
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();
await page.GotoAsync("https://example.com");
await context.RouteAsync("**/popup.html", async (route) =>
{
await route.FulfillAsync(new()
{
Status = 200,
ContentType = "text/html",
Body = "<button id=btnOk onclick=\"window.close();\">Close Me</button>"
});
});
await page.SetContentAsync(@"
<button onclick=""window.open('https://example.com/popup.html')"" id=button>Button</button>
<script>
button.addEventListener('click', () => {
const popup = window.open('https://example.com/popup.html');
popup.onload = () => {
popup.document.querySelector('button').click();
};
});
</script>
");
var popup = await page.RunAndWaitForPopupAsync(async () => {
await page.GetByRole(AriaRole.Button, new() { Name = "Button" }).ClickAsync();
});
await popup.GetByRole(AriaRole.Button, new() { Name = "Close Me" }).ClickAsync(); No action needed from your side anymore. |
Can also reproduce it in Node.js, moving over to the main repo: import playwright from 'playwright';
(async () => {
const browser = await playwright.firefox.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');
await context.route('**/popup.html', async route => {
await route.fulfill({
status: 200,
contentType: 'text/html',
body: `<button id="btnOk" onclick="window.close();">Close Me</button>`
});
});
const popupPromise = page.waitForEvent('popup');
await page.evaluate(() => {
window.open('https://example.com/popup.html');
});
const popup = await popupPromise;
await popup.getByRole('button', { name: 'Close Me' }).click();
await browser.close();
})(); Expected: Passes |
Investigation notes:
So far there's no easy way to fix this on the Juggler side other than add a hack (i.e. ignore missing ACK from the As a workaround, folks should try-catch the click method that closes the page. |
System info
A popup window that includes a button which closes the window sometimes causes an Exception in playwright.
It happens about half the time (probably a race condition that depends on how fast the browser window is closed).
Source code
Expected
no exception
Actual
The text was updated successfully, but these errors were encountered: