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.

request.continue no longer working as expected with latest Puppeteer

See original GitHub issue

Puppeteer version: 1.12.2

I’ve just updated to the latest version of puppeteer and noticed part of my script has stopped working.

The code below intercepts each request and if it was a document request check the URL for duplicate paths e.g ‘example.com/login.php/login.php’. The code used to work fine with older versions of Puppeteer, but now the request.continue part of the URL no longer seems to be working. It just doesn’t alter the request url.

Has something changed for request.continue syntax in a recent version of Puppeteer??

                request.continue({
                        url: newRequestUrl
                });

remove duplicate paths e.g example.com/foobar/foobar/ -> example.com/foobar/

        await page.setRequestInterception(true);

        page.on('request', request => {
            let blocked = false;
            let hasForwardSlash = false;

            if (request.resourceType() == "document") {
                console.log("document request");
                console.log(request.url());

                let requestUrl = request.url();

                if (requestUrl.endsWith("/")) {
                    hasForwardSlash = true; // readd slashes later
                    requestUrl = requestUrl.replace(/(\/)*$/, '');
                }

              let urlIntoArray = requestUrl.split("/");

             if (urlIntoArray[urlIntoArray.length - 1] == urlIntoArray[urlIntoArray.length - 2]) {

                    let paths = urlIntoArray[urlIntoArray.length - 1];
                    let newRequestUrl = requestUrl.replace("/" + paths, "");

                    if (hasForwardSlash) {
                        newRequestUrl = newRequestUrl + "/";
                 }

                console.log(newRequestUrl);

                request.continue({
                        url: newRequestUrl
                });
                return; // prevent calling continue twice
                 }
            }
            request.continue();
           });

EDIT: Just wanted to add that i’ve just tried the above code in Puppeteer 1.3.0 and can confirm it does indeed change the request URL. So why not in the latest puppeteer?

EDIT 2: I’ve managed to narrow when it stopped working down to between Puppeteer 1.6.0 and 1.7.0. It worked in Puppeteer 1.6.0, but stops working by 1.7.0.

EDIT 3: The problem starts it Puppeteer 1.7.0 in Puppeteer 1.6.2 it works. Has something changed with the request intercepted syntax in 1.7.0?? I’ve taken a look at the docs but couldn’t find anything.

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
leem32commented, Mar 4, 2019

Yep, that’s fixed the issue. Thanks 😃

0reactions
beeblookcommented, Feb 7, 2022

So, is there any way to rewrite request url using Puppeteer >= 1.7.0 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

puppeteer request.continue can not work with header host ...
Node.js version: 8. What is the expected result? I want override the request's host in header. Such as a request url: http ...
Read more >
Troubleshooting - Puppeteer
This means that the browser was downloaded but failed to be extracted correctly. The most common cause is a bug in Node.js v14.0.0...
Read more >
How To Write End-to-End Tests in Node.js Using Puppeteer ...
Now, you will write tests to validate that the account creation works as expected. But before you proceed, you have to decide what...
Read more >
This version has been deprecated - puppeteer - npm
A high-level API to control headless Chrome over the DevTools Protocol. Latest version: 19.4.1, last published: a day ago.
Read more >
Avoiding hard waits in Playwright and Puppeteer
Looking to solve the issue of a page or element not being loaded, ... and our script continues executing as planned, we are...
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