question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] New tab with redirection, can't verify initial url

See original GitHub issue

Context:

  • Playwright Version: 1.3.0
  • Operating System: windows
  • Node.js version: v14.2.0
  • Browser: chromium
  • Extra:

Code Snippet

Test repository to see the bug in action (both server and e2e-tests project are provided): https://github.com/boogie77/playwright-redirect-detection

Describe the bug

The issue is related to new tab being opened with initial URL /foo that is resolved (status 307, to /bar) with redirection to /bar URL. Playwright resolves context.waitForEvent('page') too late, and we can’t verify the initial URL (/foo). When it’s resolved it’s already on /bar.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
pavelfeldmancommented, Sep 9, 2020

Yes, you won’t get another route attempt because you gave it away to the network stack and network stack handles the redirects. But you can still traverse the redirect chain:

        let request;
        await context.route('**/*', route => {
            if (!request)
                request = route.request();
            route.continue().catch(e => {});
        });
        const [newPage] = await Promise.all([context.waitForEvent('page'), page.click('#myButton')]);
        await context.unroute('**/*');
        for (let r = request; r; r = r.redirectedTo())
            console.log(r.url());
4reactions
boogie77commented, Sep 7, 2020

That’s expected - Chromium will create the page after the navigation commits and this commit follows the redirects that are handled in the browser. If you’d like to assert those, you can intercept the network with context.route(). It’ll capture the original request to /foo:

context.route('**/*', route =>{
  console.log(route.request().url());
  route.continue();
});

You can do that before you click in your test and save the redirect url chain.

Thanks, I tried exacly this before reporting this “issue” above, but it didn’t work in my case. Seems like network interception is not always reliable when it comes to redirects.

When there are multiple redirects it’s not catching all of the requests, example (code https://github.com/boogie77/playwright-redirect-detection/blob/multiple_redirections/server/src/app.js#L18): Redirect chain:

  • / button click
  • open new tab to url /foo
  • response with redirect to /secondJump
  • response with redirect to /thirdJump
  • response with redirect to /bar
  • website content is loaded

What we get from network log:

http://localhost:3000/
http://localhost:3000/foo

In my production app tests I actually don’t even get the initial url context.route, meaning I don’t even see /foo (chrome extension opening new tab).

Redirects in devtools: image

@pavelfeldman Is this expected?


PS. Something weird I noticed is that when I enable devtools, the same network log from context.route is actually changed, it outputs only:

http://localhost:3000/
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Solve This Webpage has a Redirect Loop Problem
Solution of "This Webpage has a redirect loop" or "Error 310 (net::ERR_TOO_MANY_REDIRECTS): there were too many redirects" in Chrome and Mozilla Firefox.
Read more >
738724 - Chrome tabs not redirecting back to app without user ...
The issue we are facing is after successful sign-in , we are intercepting callback url via intent filter , which has session information...
Read more >
How does a site redirect existing tab when visiting it in a new tab
If I use that link, it: Briefly opens the tab correctly; The tab closes; The original tab (where I clicked the link) redirects...
Read more >
How To Fix Google Chrome Redirects - YouTube
How To Fix Google Chrome Redirects - Remove Chrome Redirect Virus · https://youtu.be/pRdbLEbuhrQ How to Change the Default Search in Google ...
Read more >
Bug: Open this link in a new window - Progress Community
'Open this link in a new window' redirect page feature does not work as expected, it open in a browser tab instead of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found