Open
Description
Version
1.52.0
Steps to reproduce
- Create
bug.html
with this HTML:
<!DOCTYPE html>
<html>
<head>
<title>Tab and Popup</title>
</head>
<body>
<button onclick="openTabAndPopup()">Open Tab and Popup</button>
<script>
function openTabAndPopup() {
const newTab = window.open('', '_blank');
if (newTab) {
newTab.document.write(`
<html>
<head><title>New Tab</title></head>
<body>
<h1>New Tab Content</h1>
<script>
window.onload = function() {
const popup = window.open('', '', 'width=300,height=200');
if (popup) {
popup.document.write('<p>This is a popup from the new tab.</p>');
popup.document.close();
window.close(); // Close the tab
} else {
alert('Popup was blocked.');
}
};
<\/script>
</body>
</html>
`);
newTab.document.close();
} else {
alert('Tab was blocked.');
}
}
</script>
</body>
</html>
- Run codegen
playwright codegen ~/<path>/bug.html
- Click button to open popup
- You should now see the following recorded steps:
using Microsoft.Playwright;
using System;
using System.Threading.Tasks;
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false,
});
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();
await page.GotoAsync("file:///Users/<user>/Desktop/bug.html");
var page2 = await page.RunAndWaitForPopupAsync(async () =>
{
await page.GetByRole(AriaRole.Button, new() { Name = "Open Tab and Popup" }).ClickAsync();
});
await page1.CloseAsync();
Expected behavior
Playwright to be able to keep track of tabs and popups opened and closed referring real variable names.
Actual behavior
Playwright refers a non-existing variable page1
, specifically the last line:
await page1.CloseAsync();
page1
never existed.
Additional context
No response
Environment
- Operating System: [macOS Sequoia 15.5]
- CPU: [arm64]
- Browser: [All]
- .NET Version (TFM): [net8.0]
- Other info: