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

0.2.2 • Public • Published

puppeteer-extra-plugin-interceptor

A puppeteer-extra plugin that simplifies request interception and response modification.

Status : Experimental

The underlying APIs in the Chrome Devtools Protocol are all labeled "Experimental" so this plugin should be considered experimental as well.

Who is this for

  • Developers troubleshooting in production
  • QA Engineers
  • Reverse Engineers
  • Penetration Testers

Documentation

Please see puppeteer-interceptor. This is just a wrapper to use with puppeteer-extra's plugin system.

Installation

$ npm install puppeteer-extra-plugin-interceptor

Usage

const puppeteer = require('puppeteer-extra');
const { interceptor, patterns } = require('puppeteer-extra-plugin-interceptor');
 
puppeteer.use(interceptor());
 
(async function main(){
  const browser = await puppeteer.launch();
 
  const [ page ] = await browser.pages();
 
  page.intercept(patterns.Script('*'), { onResponseReceived: (response) => {
    console.log(`Response is ${response.body} bytes`);
  }});
 
})()

Example

This example uses Prettier to automatically intercept and prettify all JavaScript.

const puppeteer = require('puppeteer-extra');
const { interceptor, patterns } = require('puppeteer-extra-plugin-interceptor');
 
puppeteer.use(interceptor());
 
const prettier = require('prettier');
 
function transform(response) {
  response.body = prettier.format(response.body, {parser:'babel'});
  return response;
}
 
(async function main(){
  const browser = await puppeteer.launch({
    headless:false,
    defaultViewport:null,
    args: ['--window-size=1920,1170','--window-position=0,0']
  });
 
  const [ page ] = await browser.pages();
 
  page.intercept(patterns.Script('*'), {onResponseReceived: transform});
 
  // intercept URLs in new tabs
  browser.on('targetcreated', async (target) => {
    const page = await target.page();
    if (page) page.intercept(urlPatterns, transform);
  });
 
})()

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.249latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.249
0.2.10
0.2.02

Package Sidebar

Install

npm i puppeteer-extra-plugin-interceptor

Weekly Downloads

51

Version

0.2.2

License

ISC

Unpacked Size

9.05 kB

Total Files

8

Last publish

Collaborators

  • jsoverson