Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

puppeteer-page-proxy

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

puppeteer-page-proxy

Additional Node.js module to use with 'puppeteer' for setting proxies per page basis.

  • 1.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6K
decreased by-8.91%
Maintainers
1
Weekly downloads
 
Created
Source

puppeteer-page-proxy

Additional Node.js module to use with 'puppeteer' for setting proxies per page basis.

Uses (http | https | socks)-proxy-agent to achieve the desired results.

This small module consists of a class and a function taken from ppspider.

All credit for the original code goes to the author @xiyuan-fengyu.

Installation

npm i puppeteer-page-proxy

Methods

PageProxy(page, proxy[, enableCache])
  • page <object> Page object to set a proxy for.
  • proxy <string> Proxy to use in the current page. Must begin with a protocol e.g. http://, https://, socks://.
  • enableCache <boolean> Whether to enable caching. Defaults to true.
PageProxy.lookup(page[, lookupService, isJSON, timeout])
  • page <object> Page object to execute the request on.
  • lookupService <string> External lookup service to request data from. Fetches data from api.ipify.org by default.
  • isJSON <boolean> Whether to JSON.parse the received response. Defaults to true.
  • timeout <number|string> Time in milliseconds after which the request times out. Defaults to 30000 ms.
  • returns: <Promise> Promise which resolves to the response of the lookup request.

Examples

General usage:
const puppeteer = require('puppeteer');
const useProxy = require('puppeteer-page-proxy');

(async () => {
    let site = 'https://example.com';
    let proxy1 = 'http://host:port';
    let proxy2 = 'https://host:port';
    let proxy3 = 'socks://host:port';
    
    const browser = await puppeteer.launch({headless: false});

    const page1 = await browser.newPage();
    await useProxy(page1, proxy1);
    await page1.goto(site);

    const page2 = await browser.newPage();
    await useProxy(page2, proxy2);
    await page2.goto(site);

    const page3 = await browser.newPage();
    await useProxy(page3, proxy3);
    await page3.goto(site);
})();
Lookup IP used by proxy -> Useful in headless environment:
const puppeteer = require('puppeteer');
const useProxy = require('puppeteer-page-proxy');

(async () => {
    let site = 'https://example.com';
    let proxy1 = 'http://host:port';
    let 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);
})();

Keywords

FAQs

Package last updated on 08 Jan 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc