0.1.0 • Published 5 years ago
puppeteer-extra-interceptor v0.1.0
puppeteer-extra-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-interceptor
Usage
const puppeteer = require('puppeteer-extra');
const { interceptor, patterns } = require('puppeteer-extra-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-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);
});
})()
0.1.0
5 years ago