0.3.1 • Published 2 years ago

puppeteer-fetch v0.3.1

Weekly downloads
65
License
Apache-2.0
Repository
github
Last release
2 years ago

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>;
}
0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.7

3 years ago

0.1.4

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago