[BUG] When clicking on a link navigating away from the website, playwright throws a removeFrameSession failure
See original GitHub issueContext:
- Playwright Version: 0.13.0
- Operating System: Mac
Code Snippet
it('should work', async () => {
console.log('goto');
await page.goto(
'https://journal.cnishina.dev/2020/04/create-mp4-from-screencast.html');
await new Promise((resolve) => {
setTimeout(resolve, 500);
});
console.log('click journal');
await page.click('a[href="https://journal.cnishina.dev/"]');
console.log('youtube');
await page.click('a[href="https://youtu.be/dQw4w9WgXcQ"]');
});
Describe the bug
As a person writing a test, if I click on a link that navigates me away from the page, then it should not throw an error. I noticed this when I was clicking the a[href="https://youtu.be/dQw4w9WgXcQ"]
. Clicking on this throws an error. I am either looking for documentation explaining targetId and sessionId and why this does not work when this happens (what the workflow should be if we decide to click on a link navigating us away from the main page) or to fix it with:
removeFrameSession(targetId) {
const frameSession = this._sessions.get(targetId);
if (!frameSession)
return;
// Frame id equals target id.
const frame = this._page._frameManager.frame(targetId);
if (frame) {
this._page._frameManager.removeChildFramesRecursively(frame);
frameSession.dispose();
this._sessions.delete(targetId);
}
}
This just changes the assert(frame);
and puts it into a conditional. I’ve tried out this change and it appears to work but might not be the right fix. Let me know and I can put in a PR this week. Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
click on a link is not working in playwright - Stack Overflow
The root problem seems to be that Playwright is not recognizing the change of the visiblity in the elements after
Read more >navigation failed because page was closed! - You.com
Error is thrown at the point when I await page.goto(url). Navigation failed because page was closed is the error. Things attempted to no...
Read more >Back to Basics: Non-Navigating Links for JavaScript Handling
Empty HREF links might be tempting but they are problematic as they basically mean re-navigate the current page. It's like a Refresh operation ......
Read more >When to use target="_blank" | CSS-Tricks
Anchor links1 may have a target attribute which controls what happens when that link is clicked. One of the possible values of that ......
Read more >should JavaScript be allowed to change a web link *after* you ...
The next bit of the trick involves using the onclick event to change the href attribute of the link you just clicked. When...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here’s my sample code. This runs with
npm test
.https://github.com/cnishina/protractor-experiments/tree/master/playwright-issue-1762
Sounds good. I’ll have something in by the end of the day…