puppeteer-fetch
v0.3.1
Published
Fetch with Puppeteer, just like node-fetch, but use puppeteer as the driver
Downloads
141
Maintainers
Readme
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>;
}