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

pupeteer-proxy

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pupeteer-proxy

Proxies Puppeteer Page requests.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

puppeteer-proxy 🎎

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

Proxies Puppeteer Page requests.

  • Allows to change proxy per Page and per Request.
  • Allows to authenticate using http://username:password@proxy schema.
  • Handles cookies.
  • Handles binary files.
  • Supports custom HTTP(S) agents.

Motivation

This package addresses several issues with Puppeteer:

  • It allows to set a proxy per Page and per Request (#678)
  • It allows to authenticate against proxy when making HTTPS requests (#3253)

The side-benefit of this implementation is that it allows to route all traffic through Node.js, i.e. you can use externally hosted Chrome instance (such as Browserless.io) to render DOM & evaluate JavaScript, and route all HTTP traffic through your Node.js instance.

The downside of this implementation is that it will introduce additional latency, i.e. requests will take longer to execute as request/ response will need to be always exchanged between Puppeteer and Node.js.

Implementation

puppeteer-proxy intercepts requests after it receives the request metadata from Puppeteer. puppeteer-proxy uses Node.js to make the HTTP requests. The response is then returned to the browser. When using puppeteer-proxy, browser never makes outbound HTTP requests.

Setup

You must call page.setRequestInterception(true) before using pageProxy.proxyRequest.

API

import {
  Agent as HttpAgent,
} from 'http';
import {
  Agent as HttpsAgent,
} from 'https';
import type {
  Page,
  Request,
} from 'puppeteer';
import {
  proxyRequest,
} from 'puppeteer-proxy';

/**
 * @property agent HTTP(s) agent to use when making the request.
 * @property page Instance of Puppeteer Page.
 * @property proxyUrl HTTP proxy URL. A different proxy can be set for each request.
 * @property request Instance of Puppeteer Request.
 */
type ProxyRequestConfigurationType = {|
  +agent?: HttpAgent | HttpsAgent,
  +page: Page,
  +proxyUrl?: string | { http: string, https: string },
  +request: Request,
|};

proxyRequest(configuration: ProxyRequestConfigurationType): PageProxyType;

Usage

Making a GET request using proxy

import puppeteer from 'puppeteer';
import {
  proxyRequest,
} from 'puppeteer-proxy';

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  await page.setRequestInterception(true);

  page.on('request', async (request) => {
    await proxyRequest({
      page,
      proxyUrl: 'http://127.0.0.1:3000',
      request,
    });
  });

  await page.goto('http://gajus.com');
})();

Keywords

FAQs

Package last updated on 31 Oct 2024

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