puppeteer-fetch
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

puppeteer-fetch

Table of Contents

About

Fetch with Puppeteer, just like node-fetch, but use puppeteer as the driver.

Getting Started

const fetch = require("puppeteer-fetch").default;

(async () => {
  const response = await fetch("https://jsonplaceholder.typicode.com/posts", {
    method: "POST",
    body: JSON.stringify({
      title: "foo",
      body: "bar",
      userId: 1,
    }),
    headers: {
      "Content-type": "application/json; charset=UTF-8",
    },
  });
  const ok = response.ok;
  if (ok) {
    const result = await response.json();
    console.log("result", result);
    // print { title: 'foo', body: 'bar', userId: 1, id: 101 }
  }
})();

Installing

npm i puppeteer-fetch

Usage

fetchOptions see Fetch_API

puppeteerConfig see puppeteer

const fetch = require('puppeteer-fetch');

fetch('<url>', fetchOptions, {
  puppeteerConfig: IPuppeteerConfig,
  timeout: number,
  puppeteer: PuppeteerNode
});

// you can pass a puppeteer instant, like puppeteer-extra

interface IPuppeteerConfig {
  launchOptions?: LaunchOptions & ChromeArgOptions & BrowserOptions;
  userAgent?: string;
  viewPort?: {
    width: number;
    height: number;
    deviceScaleFactor?: number;
    isMobile?: boolean;
    isLandscape?: boolean;
    hasTouch?: boolean;
  };
  waitFor?: WaitForOptions;
  extraHTTPHeaders?: Record<string, string>;
}

Package Sidebar

Install

npm i puppeteer-fetch

Weekly Downloads

74

Version

0.3.1

License

Apache-2.0

Unpacked Size

47.7 kB

Total Files

28

Last publish

Collaborators

  • theowenyoung