Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

77
Views
Puppeteer how to intercept multiple requests

I want to intercept multiple request and I'am not able to find a working solution.

  1. Abort all requests for stylesheets and images for request 1
  2. Inject POST request payload for request 2 in a loop

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!