I want to intercept multiple request and I'am not able to find a working solution.
As far as I understood I can only have one request interceptor?!
Currently my interceptor is in the loop to intercept the payload into the POST request.
const siteResponse = await page.goto(siteUrl, { waitUntil: 'load', timeout: 0 });
...
for (var item of items) {
const payload = { prop: item };
await page.setRequestInterception(true);
page.once('request', request => {
request.continue({
'method': 'POST',
'postData': JSON.stringify(payload),
'headers': { ...request.headers()}
});
page.setRequestInterception(false);
});
const addItemResponse = await page.goto(addItemUrl, { waitUntil: 'load', timeout: 0 });
}
This works like a sharm. But I'm not able to intercept request 1 to abort requests for stylesheets and images.
Any ideas how to design the code to intercept the requests in the loop with the payload and abort stylesheets and image requests for the first request?
Your question isn't entirely clear to me, but it sounds like you might want to explore request interception in puppeteer a little more. Here is puppeteer's official documentation on request interception. They actually provide an example that seems pretty close to your desired implementation.
You can also use the Chrome DevTools Protocol to tap into more request data if can't get what you're looking for through the request interception interface. I've answered a question on that previously, here.