How to use the puppeteer-core.createBrowserFetcher function in puppeteer-core

To help you get started, we’ve selected a few puppeteer-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github curvegrid / testcafe-browser-provider-puppeteer-core / src / index.js View on Github external
async _downloadBrowser (revision) {
        const downloadHost = process.env.PUPPETEER_DOWNLOAD_HOST; // defaults to https://storage.googleapis.com if null
        const browserFetcher = puppeteer.createBrowserFetcher({ host: downloadHost });

        // same logic as puppeteer
        revision = revision || process.env.PUPPETEER_CHROMIUM_REVISION || require('puppeteer-core/package.json').puppeteer.chromium_revision;
        const revisionInfo = browserFetcher.revisionInfo(revision);

        // do nothing if the revision is already downloaded.
        if (revisionInfo.local)
            return;

        await browserFetcher.download(revisionInfo.revision, this._downloadProgressCallback(revision));
    },
github mbalabash / estimo / scripts / chromeDetection.js View on Github external
async function downloadChromium() {
  const browserFetcher = puppeteer.createBrowserFetcher({
    path: chromeTempPath,
    host: downloadHost,
  })

  const revision =
    process.env.PUPPETEER_CHROMIUM_REVISION ||
    process.env.npm_config_puppeteer_chromium_revision ||
    process.env.npm_package_config_puppeteer_chromium_revision ||
    pptrCoreJson.puppeteer.chromium_revision
  const revisionInfo = browserFetcher.revisionInfo(revision)

  // If already downloaded
  if (revisionInfo.local) return revisionInfo

  try {
    console.log(`Downloading Chromium r${revision}...`)
github GoogleChromeLabs / carlo / lib / find_chrome.js View on Github external
async function downloadChromium(options, targetRevision) {
  const browserFetcher = puppeteer.createBrowserFetcher({ path: options.localDataDir });
  const revision = targetRevision || require('puppeteer-core/package.json').puppeteer.chromium_revision;
  const revisionInfo = browserFetcher.revisionInfo(revision);

  // Do nothing if the revision is already downloaded.
  if (revisionInfo.local)
    return revisionInfo;

  // Override current environment proxy settings with npm configuration, if any.
  try {
    console.log(`Downloading Chromium r${revision}...`);
    const newRevisionInfo = await browserFetcher.download(revisionInfo.revision);
    console.log('Chromium downloaded to ' + newRevisionInfo.folderPath);
    let localRevisions = await browserFetcher.localRevisions();
    localRevisions = localRevisions.filter(revision => revision !== revisionInfo.revision);
    // Remove previous chromium revisions.
    const cleanupOldVersions = localRevisions.map(revision => browserFetcher.remove(revision));
github grafana / grafana / packages / grafana-toolkit / src / e2e / install.ts View on Github external
export const downloadBrowserIfNeeded = async (): Promise => {
  const browserFetcher = puppeteer.createBrowserFetcher();
  const localRevisions = await browserFetcher.localRevisions();
  if (localRevisions && localRevisions.length > 0) {
    console.log('Found a local revision for browser, exiting install.');
    return;
  }

  console.log('Did not find any local revisions for browser, downloading latest this might take a while.');
  await browserFetcher.download(constants.chromiumRevision, (downloaded, total) => {
    if (downloaded === total) {
      console.log('Chromium successfully downloaded');
    }
  });
};
github Munter / subfont / lib / HeadlessBrowser.js View on Github external
async function downloadOrLocatePreferredBrowserRevision() {
  const browserFetcher = puppeteer.createBrowserFetcher();
  const preferredRevision = puppeteer._launcher._preferredRevision;
  const localRevisions = await browserFetcher.localRevisions();
  let revisionInfo;
  if (localRevisions.includes(preferredRevision)) {
    revisionInfo = await browserFetcher.revisionInfo(preferredRevision);
  } else {
    console.log(`Downloading Chromium ${preferredRevision}`);
    revisionInfo = await browserFetcher.download(preferredRevision);
  }
  return puppeteer.launch({
    executablePath: revisionInfo.executablePath
  });
}
github onderceylan / pwa-asset-generator / src / helpers / installer.ts View on Github external
const getBrowserFetcher = (): BrowserFetcher => {
  const downloadHost =
    process.env.PUPPETEER_DOWNLOAD_HOST ||
    process.env.npm_config_puppeteer_download_host ||
    process.env.npm_package_config_puppeteer_download_host;
  if (browserFetcher) {
    return browserFetcher;
  }

  browserFetcher = puppeteer.createBrowserFetcher({ host: downloadHost });
  return browserFetcher;
};
github grafana / grafana / packages / grafana-toolkit / src / e2e / launcher.ts View on Github external
export const launchBrowser = async (): Promise => {
  const browserFetcher = puppeteer.createBrowserFetcher();
  const localRevisions = await browserFetcher.localRevisions();
  if (localRevisions.length === 0) {
    throw new Error('Could not launch browser because there is no local revisions.');
  }

  let executablePath = null;
  executablePath = browserFetcher.revisionInfo(localRevisions[0]).executablePath;

  const browser = await puppeteer.launch({
    headless: process.env.BROWSER ? false : true,
    slowMo: process.env.SLOWMO ? 100 : 0,
    defaultViewport: {
      width: 1920,
      height: 1080,
      deviceScaleFactor: 1,
      isMobile: false,