Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
puppeteer-page-proxy
Advanced tools
Additional Node.js module to use with 'puppeteer' for setting proxies per page basis.
Additional Node.js module to use with puppeteer for setting proxies per page basis.
Forwards intercepted requests from the browser to Node.js where it handles the request then returns the response to the browser, changing the proxy as a result.
npm i puppeteer-page-proxy
pageOrReq
<object> 'Page' or 'Request' object to set a proxy for.proxy
<string> Proxy to use in the current page.
page
<object> 'Page' object to execute the request on.lookupService
<string> External lookup service to request data from.
api.ipify.org
by default.isJSON
<boolean> Whether to JSON.parse the received response.
true
.timeout
<number|string> Time in milliseconds after which the request times out.
30000
ms.NOTE: By default this method expects a response in JSON format and JSON.parse's it to a usable javascript object. To disable this functionality, set isJSON
to false
.
const puppeteer = require('puppeteer');
const useProxy = require('puppeteer-page-proxy');
(async () => {
const site = 'https://example.com';
const proxy = 'http://host:port';
const proxy2 = 'https://host:port';
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await useProxy(page, proxy);
await page.goto(site);
const page2 = await browser.newPage();
await useProxy(page2, proxy2);
await page2.goto(site);
})();
await useProxy(page, proxy);
await page.goto(site, {waitUntil: 'networkidle2'});
await useProxy(page, proxy2);
await page.reload();
const puppeteer = require('puppeteer');
const useProxy = require('puppeteer-page-proxy');
(async () => {
const site = 'https://example.com';
const proxy = 'socks://host:port';
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', async req => {
await useProxy(req, proxy); // 'req' as argument
});
await page.goto(site);
})();
When changing proxies this way, the request object itself is passed as the first argument. Now 'proxy' can be changed every request.
Leaving it as is will have the same effect as useProxy(page, proxy)
, meaning that the same proxy will be used for all requests within the page.
NOTE: It is necessary page.setRequestInterception() to true, otherwise the function will fail.
await page.setRequestInterception(true);
page.on('request', async req => {
if (req.resourceType() === 'image') {
req.abort();
} else {
await useProxy(req, proxy);
}
});
Internally puppeteer-page-proxy
handles the request which was passed in, then responds back to the browser using the interception method request.respond(). Calling this method will fulfill the request with a given response and set the proxy.
NOTE: Since all requests can be handled exactly once, it's not possible to call other interception methods e.g. request.abort(), request.continue() after calling useProxy()
, without getting a 'Request is already handled!' error message.
const proxy = 'https://login:pass@host:port';
const puppeteer = require('puppeteer');
const useProxy = require('puppeteer-page-proxy');
(async () => {
const site = 'https://example.com';
const proxy1 = 'http://host:port';
const proxy2 = 'https://host:port';
const browser = await puppeteer.launch({headless: false});
/**1*/
const page1 = await browser.newPage();
await useProxy(page1, proxy1);
let data = await useProxy.lookup(page1); // Waits until done, 'then' continues
console.log(data.ip);
await page1.goto(site);
/**2*/
const page2 = await browser.newPage();
await useProxy(page2, proxy2);
useProxy.lookup(page2).then(data => { // Executes and 'comes back' once done
console.log(data.ip);
});
await page2.goto(site);
})();
[1.2.0] - 2020-02-09
FAQs
Additional Node.js module to use with 'puppeteer' for setting proxies per page basis.
The npm package puppeteer-page-proxy receives a total of 2,362 weekly downloads. As such, puppeteer-page-proxy popularity was classified as popular.
We found that puppeteer-page-proxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.