Reputation: 463
I'm crawling data from a page which contains an iframe. The sample code
await page.setRequestInterception(true);
page.on('request', request => {
console.log(request.url());
//.........................
request.continue();
});
await page.goto(url, {waitUtil: 'networkidle0', timeout: 30000});
//..................
This code only showed requests on main frame, it couldn't catch any requests from the inner iframe. In Chrome network inspection, I saw many XHR requests from this page.
Is there a way to catch requests on iframe ? Many thanks !
Upvotes: 2
Views: 4551
Reputation: 822
Seems that adding these to browser startup options may fix the problem:
args: [
'--disable-web-security',
'--disable-features=IsolateOrigins,site-per-process'
]
Update 2023: Seems Puppeteer will remove this in future versions. At the moment you can enable intercepting by adding this extra argument:
--disable-site-isolation-trials
Upvotes: 2
Reputation: 463
When I set puppeteer headless = true, the above code has worked. It catches all requests on all iframes on my crawling website.
Upvotes: 5