request.continue no longer working as expected with latest Puppeteer
See original GitHub issuePuppeteer 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:
- Created 5 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top GitHub Comments
Yep, that’s fixed the issue. Thanks 😃
So, is there any way to rewrite request url using Puppeteer >= 1.7.0 ?