puppeteer-extra-plugin-replayer
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

puppeteer-extra-plugin-replayer

Replay and modify caught requests by intercepting network activity within puppeteer scripts.

This package is prepared for:

  • QA Engineers
  • Reverse Engineers
  • Scrapers
  • Penetration Testers

Installation

npm install puppeteer-extra-plugin-replayer

How to use

There are two scenarios to catch ongoing requests:

  • initial requests when the site opens
  • requests are triggered by user actions such as mouse click or search

In the first scenario, the page initiating must be done in the trigger function.

(async () => {
    const request = await page.catchRequest({
        pattern: /hashflags.json/
    }, () => page.goto("https://twitter.com"));

    const response = await request.replay();
})();

In the second scenario, the interaction function that triggers the wanted request must be called in the trigger function of the catchReques method.

(async () => {
    await page.goto("https://twitter.com")

    //...

    const request = await page.catchRequest({
        pattern: /onboarding\/task\.json\?flow_name=login/
    }, async () => {
        await page.waitForSelector("a[href='/login']")
        await page.click("a[href='/login']")
    });

    await request.replay();
})();

You can see original and replayed requests on the network tab in CDP.

Screen Shot 2022-10-11 at 9 40 24 AM

API

page.catchRequest(PatternObject, triggerFunction)

The plugin provides a function as .catchRequest(PatternObject, triggerFunction), which can be used to catch ongoing requests. The function returns an extended version of HTTPRequest object, which includes .replay() method.

request.replay(RequestInit?)

The .replay() method takes an optional argument as an extended version of RequestInit object that includes functionated version of strign parameters such url, method and headers, and body.

Package Sidebar

Install

npm i puppeteer-extra-plugin-replayer

Weekly Downloads

0

Version

1.0.5

License

ISC

Unpacked Size

33.5 kB

Total Files

9

Last publish

Collaborators

  • sametcodes