GithubHelp home page GithubHelp logo

geekwolverine / puppeteer-chromium-resolver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cenfun/puppeteer-chromium-resolver

0.0 1.0 0.0 100 KB

Tool to resolve puppeteer and chromium faster

Home Page: https://www.npmjs.com/package/puppeteer-chromium-resolver

License: MIT License

JavaScript 100.00%

puppeteer-chromium-resolver's Introduction

Puppeteer Chromium Resolver

Tool to resolve puppeteer and chromium faster, detect local installed chromium, download chromium with custom mirror host, cache chromium revision out of node_modules, test chromium headless being launchable.

  • Tool to customize puppeteer
  • Detect local chromium automatically
  • Download chromium from custom mirror host
  • Cache chromium to local folder
  • Try launching chromium and resolve launchable and version
  • Resolve chromium executablePath and puppeteer

Install

npm i puppeteer-chromium-resolver

Usage

[Async] dynamic detection and downloading chromium

(async () => {
    const PCR = require("puppeteer-chromium-resolver");
    const option = {
        revision: "",
        detectionPath: "",
        folderName: ".chromium-browser-snapshots",
        defaultHosts: ["https://storage.googleapis.com", "https://npm.taobao.org/mirrors"],
        hosts: [],
        cacheRevisions: 2,
        retry: 3,
        silent: false
    };
    const stats = await PCR(option);
    const browser = await stats.puppeteer.launch({
        headless: false,
        args: ["--no-sandbox"],
        executablePath: stats.executablePath
    }).catch(function(error) {
        console.log(error);
    });
    const page = await browser.newPage();
    await page.goto("https://www.npmjs.com/package/puppeteer-chromium-resolver");
    await browser.close();
})();

[Sync] chromium will be pre-downloaded when PCR installation, so calling getStats() will get PCR stats from previous installation.

const PCR = require("puppeteer-chromium-resolver");
const stats = PCR.getStats();
if (stats) {
    stats.puppeteer.launch({
        headless: false,
        args: ["--no-sandbox"],
        executablePath: stats.executablePath
    }).then(function(browser){
        //...
    }).catch(function(error) {
        console.log(error);
    });
}

Option from root package.json with "pcr" object

{
    "name": "",
    "version": "",
    "dependencies": {},

    "pcr": {
        "revision": "869685"
    }

}

Return Stats

Property Type
revision String current chromium revision
executablePath String chromium executable path
folderPath String chromium folder path
local Boolean exists local chromium
url String chromium download url
launchable Boolean chromium launchable
chromiumVersion String chromium version
puppeteerVersion String puppeteer version
puppeteer Object puppeteer module

How to make puppeteer work with puppeteer-chromium-resolver

  • 1, Stop the automatic download of Chromium with following settings in .npmrc
puppeteer_skip_download = true
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = true

(one more setting for puppeteer v2.x)

  • 2, Sets env PUPPETEER_EXECUTABLE_PATH to PCR executablePath globally or pass in launch option executablePath
(async () => {

    const PCR = require("puppeteer-chromium-resolver");
    const puppeteer = require("puppeteer");
    const stats = await PCR();
    //update global env
    process.env.PUPPETEER_EXECUTABLE_PATH = stats.executablePath;

    //or specify executablePath
    const browser = await puppeteer.launch({
        executablePath: stats.executablePath,
        headless: false
    });

})();

Troubleshooting

  • CentOS: error while loading shared libraries: libatk-1.0.so.0: cannot open shared objecsuch file or directory
# Install dependencies:
yum install -y alsa-lib.x86_64 \
atk.x86_64 \
cups-libs.x86_64 \
gtk3.x86_64 \
ipa-gothic-fonts \
libXcomposite.x86_64 \
libXcursor.x86_64 \
libXdamage.x86_64 \
libXext.x86_64 \
libXi.x86_64 \
libXrandr.x86_64 \
libXScrnSaver.x86_64 \
libXtst.x86_64 \
pango.x86_64 \
xorg-x11-fonts-100dpi \
xorg-x11-fonts-75dpi \
xorg-x11-fonts-cyrillic \
xorg-x11-fonts-misc \
xorg-x11-fonts-Type1 \
xorg-x11-utils

# After installing dependencies you need to update nss library:
yum update nss -y

more https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

CHANGELOG

CHANGELOG.md

puppeteer-chromium-resolver's People

Contributors

cenfun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.