Page.setRequestInterception Redirection Issue
See original GitHub issueSteps to reproduce
When page.setRequestInterception(true); redirections don’t happen correctly
Tell us about your environment:
- Puppeteer version: 1.7.0
- Platform / OS version: Mac 10.13.6
- URLs (if applicable):
- Node.js version: 8.11.4
What steps will reproduce the problem?
const puppeteer = require('puppeteer');
async function checkLink() {
let browser = await puppeteer.launch({ headless: true });
let page = await browser.newPage();
await page.setRequestInterception(true);
await page.setUserAgent('Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5 Build/LMY48B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.65 Mobile Safari/537.36');
let redirects = {};
page.on('request', request => {
if (['image', 'stylesheet', 'font', 'script'].indexOf(request.resourceType()) !== -1) {
request.abort();
} else {
request.continue();
}
});
page.on('requestfailed', (req, resp) => {
let failureText = req.failure().errorText;
if (failureText == 'net::ERR_ABORTED' || failureText == 'net::ERR_UNKNOWN_URL_SCHEME') {
redirects[req.url()] = {
url: req.url(),
status: req.response() ? req.response().status() : 200
}
}
});
page.on('response', response => {
let responseHeaders = response.headers();
redirects[response.request().url()] = {
url: response.request().url(),
status: response.status()
}
})
try {
const response = await page.goto('https://demo.vnative.net/5bc72b2fb6920d1c45045435', {
timeout: 60000,
waitUntil: ['domcontentloaded', 'networkidle0', 'networkidle2']
});
} catch (e) {
console.log(e);
}
await page.close();
await browser.close();
return redirects;
}
checkLink().then(d => console.log(d)).catch(e => console.log(e));
- Save the code in the file and run it with Node
What is the expected result?
{ 'https://demo.vnative.net/5bc72b2fb6920d1c45045435':
{ url: 'https://demo.vnative.net/5bc72b2fb6920d1c45045435',
status: 200 },
'https://demo.vnative.net/a/v/blue.gif?ps=NDE=&ans=ODY=&cd=SkC2TvBoTprlPg8EQF9h3YrbSekmTEz2hDX3kC3Owft9LfldPd5n8tA4t18A1Ag42-Lb38mb6ZxXb3N0_uC64IaN089hlidkqkVBCbLi-fJ2LzMFtwT2Xlpt--dSmcxZQGjVhxdnZcHNIIir6Z9hSDNkK30eVJHsUixonheL-NokZstGNDAAikkzkg8ZoFJCH3nfVeXrU7X7y2QlYAiKTND0-l1MSAcq55zTzyx5JsW9j0fLgYi53Ssib4E5hkJgLHjGSQyy7fB9n0R9EjDzfLE7cGVlkcVbmaZVRjCaWXK5oAdAO94UqJF1PBg0C0Ss':
{ url: 'https://demo.vnative.net/a/v/blue.gif?ps=NDE=&ans=ODY=&cd=SkC2TvBoTprlPg8EQF9h3YrbSekmTEz2hDX3kC3Owft9LfldPd5n8tA4t18A1Ag42-Lb38mb6ZxXb3N0_uC64IaN089hlidkqkVBCbLi-fJ2LzMFtwT2Xlpt--dSmcxZQGjVhxdnZcHNIIir6Z9hSDNkK30eVJHsUixonheL-NokZstGNDAAikkzkg8ZoFJCH3nfVeXrU7X7y2QlYAiKTND0-l1MSAcq55zTzyx5JsW9j0fLgYi53Ssib4E5hkJgLHjGSQyy7fB9n0R9EjDzfLE7cGVlkcVbmaZVRjCaWXK5oAdAO94UqJF1PBg0C0Ss',
status: 200 },
'https://r4i-1.tlnk.io/serve?action=click&agency_id=1371&campaign_id_android=419342&destination_id_android=433748&publisher_id=31&site_id_android=128738&ref_id=102f5382f5969ff81d4ad4d1daa910&sub_publisher=testing_31_&ios_ifa=&google_aid=&sub3=18587&ckey=15102ae1bd15946317d6bc2aa980f00e&data=5bc73d3d7b741c04afc9c39d':
{ url: 'https://r4i-1.tlnk.io/serve?action=click&agency_id=1371&campaign_id_android=419342&destination_id_android=433748&publisher_id=31&site_id_android=128738&ref_id=102f5382f5969ff81d4ad4d1daa910&sub_publisher=testing_31_&ios_ifa=&google_aid=&sub3=18587&ckey=15102ae1bd15946317d6bc2aa980f00e&data=5bc73d3d7b741c04afc9c39d',
status: 302 },
'market://details?id=jp.co.atm.vcon.jp&referrer=mat_click_id%3Db77a8e74734a1967b242af01645de275-20181017-15486':
{ url: 'market://details?id=jp.co.atm.vcon.jp&referrer=mat_click_id%3Db77a8e74734a1967b242af01645de275-20181017-15486',
status: 200 } }
The given URL redirects to a marketplace URI with opened with Android user agent but with Page.setRequestInterception -> true it fails to complete the request
What happens instead?
{ 'https://demo.vnative.net/5bc72b2fb6920d1c45045435':
{ url: 'https://demo.vnative.net/5bc72b2fb6920d1c45045435',
status: 200 },
'https://r4i-1.tlnk.io/serve?action=click&agency_id=1371&campaign_id_android=419342&destination_id_android=433748&publisher_id=31&site_id_android=128738&ref_id=102f5382f5969ff81d4ad4d1daa910&sub_publisher=testing_31_&ios_ifa=&google_aid=&sub3=18587&ckey=15102ae1bd15946317d6bc2aa980f00e&data=5bc73c95be608d04b897e13c':
{ url: 'https://r4i-1.tlnk.io/serve?action=click&agency_id=1371&campaign_id_android=419342&destination_id_android=433748&publisher_id=31&site_id_android=128738&ref_id=102f5382f5969ff81d4ad4d1daa910&sub_publisher=testing_31_&ios_ifa=&google_aid=&sub3=18587&ckey=15102ae1bd15946317d6bc2aa980f00e&data=5bc73c95be608d04b897e13c',
status: 200 } }
Instead it fails after the second request https://r4i-1.tlnk.io/serve… which is sending a 302 response with location header market://details?id=jp.co.atm.vcon.jp..
if you comment out the page.setRequestInterception everything works perfectly but unfortunately I need to intercept the requests.
Any solution / workaround would be appreciated
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Puppeteer how to send PUT request to the redirected page
When I set await page.setRequestInterception(true); and page.once('request', (req) => {...}) it sends put request to the first page which I ...
Read more >Page.setRequestInterception() method - Puppeteer
This provides the capability to modify network requests that are made by a page. Once request interception is enabled, every request will stall...
Read more >Puppeteer documentation - DevDocs
Emitted when a page issues a request. The HTTPRequest object is read-only. In order to intercept and mutate requests, see page.setRequestInterception .
Read more >Web Scraping with a Headless Browser: A Puppeteer Tutorial
Now, this is a problem if we are doing some kind of web scraping or web ... First, we launch a new headless...
Read more >puppeteer-expected.json - mozsearch - Searchfox
"Page.click should click on a span with an inline element inside (click.spec.js)": [ ... setRequestInterception should work when POST is redirected with 302 ......
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 FreeTop 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
Top GitHub Comments
Still have the same issue in 2019
I’m having the same problem.