How to use the puppeteer.createBrowserFetcher function in puppeteer

To help you get started, we’ve selected a few puppeteer 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 grafana / grafana-image-renderer / scripts / download_chromium.js View on Github external
// as for grpc download (ie darwin-x64-unknown) so we need to transform it a bit
  platform,
  arch
] = archArg.split('-');

if (platform === 'win32' && arch === 'x64') {
  platform = 'win64'
}

if (platform === 'darwin') {
  platform = 'mac'
}

const outputPath = "dist/" + (process.argv[3] || `plugin-${archArg}`);

const browserFetcher = Puppeteer.createBrowserFetcher({ platform });
const revision = puppeteerPackageJson.puppeteer.chromium_revision;

browserFetcher
  .download(revision, null)
  .then(() => {
    console.log("Chromium downloaded");
    const parts = browserFetcher.revisionInfo(revision).executablePath.split(path.sep);

      // based on where puppeteer puts the binaries see BrowserFetcher.revisionInfo()
    while (!parts[parts.length - 1].startsWith('chrome-')) {
      parts.pop()
    }

    let execPath = parts.join(path.sep);

    child_process.execSync(`cp -RP ${execPath} ${outputPath}`);
github browserless / chrome / scripts / symlink-chrome.js View on Github external
if (stderr.trim().length) {
    console.error(stderr);
    return process.exit(1);
  }

  return stdout.trim();
};

// This is used in docker to symlink the puppeteer's
// chrome to a place where most other libraries expect it
// (IE: WebDriver) without having to specify it
if (!IS_DOCKER) {
  return;
}

const browserFetcher = puppeteer.createBrowserFetcher();
const { executablePath } = browserFetcher.revisionInfo(packageJson.puppeteer.chromium_revision);

(async () => fs.existsSync(CHROME_BINARY_LOCATION) ?
  Promise.resolve() :
  exec(`ln -s ${executablePath} ${CHROME_BINARY_LOCATION}`)
)();
github yzane / vscode-markdown-pdf / extension.js View on Github external
function installChromium() {
  try {
    vscode.window.showInformationMessage('[Markdown PDF] Installing Chromium ...');
    var statusbarmessage = vscode.window.setStatusBarMessage('$(markdown) Installing Chromium ...');

    // proxy setting
    setProxy();

    var StatusbarMessageTimeout = vscode.workspace.getConfiguration('markdown-pdf')['StatusbarMessageTimeout'];
    const puppeteer = require('puppeteer');
    const browserFetcher = puppeteer.createBrowserFetcher();
    const revision = require(path.join(__dirname, 'node_modules', 'puppeteer', 'package.json')).puppeteer.chromium_revision;
    const revisionInfo = browserFetcher.revisionInfo(revision);

    // download Chromium
    browserFetcher.download(revisionInfo.revision, onProgress)
      .then(() => browserFetcher.localRevisions())
      .then(onSuccess)
      .catch(onError);

    function onSuccess(localRevisions) {
      console.log('Chromium downloaded to ' + revisionInfo.folderPath);
      localRevisions = localRevisions.filter(revision => revision !== revisionInfo.revision);
      // Remove previous chromium revisions.
      const cleanupOldVersions = localRevisions.map(revision => browserFetcher.remove(revision));

      if (checkPuppeteerBinary()) {
github accforgit / blog-data / 将自己在CSDN上的文章下载到本地并上传到掘金 / src / util.js View on Github external
const puppeteer = require('puppeteer')

// 导航超时时间
const timeout = 0
// 系统
const browserFetcher = puppeteer.createBrowserFetcher()
const platform = browserFetcher.platform()

/**
 * 有的标题中含有特殊字符,例如 / :等,无法作为文件名,所以需要清理一下
 * @param {*} filePath: 需要被清理的源文件名
 */
const clearFilePath = filePath => {
  return filePath.replace(/[\/:*?"<>|]/g, '!')
}

const sleep = (timer = 500) => {
  return new Promise(resolve => {
    const st = setTimeout(() => {
      clearTimeout(st)
      resolve()
    }, timer)
github browserless / chrome / src / config.ts View on Github external
export const CHROME_BINARY_LOCATION: string = process.env.CHROME_BINARY_LOCATION || (() => {
  // If it's installed already (docker) use it
  if (IS_DOCKER) {
    return CHROME_BINARY_DEFAULT_LOCATION;
  } else {
    // Use puppeteer's copy otherwise
    const browserFetcher = puppeteer.createBrowserFetcher();

    return browserFetcher.revisionInfo(packageJson.puppeteer.chromium_revision).executablePath;
  }
})();
github qjebbs / vscode-markdown-extended / src / services / exporter / puppeteer.ts View on Github external
private async fetchBinary(progress: Progress) {
        let pt = require('puppeteer');
        let fetcher = pt.createBrowserFetcher();
        const revision = require(path.join(context.extensionPath, 'node_modules', 'puppeteer', 'package.json')).puppeteer.chromium_revision;
        const revisionInfo = fetcher.revisionInfo(revision);
        let lastPg = 0;
        progress.report({
            message: `MarkdownExtended: Downloading dependency Chromium (0%)`,
            increment: 0
        });
        return fetcher.download(revisionInfo.revision, (downloadedBytes: number, totalBytes: number) => {
            let pg: number = ~~(downloadedBytes / totalBytes * 100);
            progress.report({
                message: `MarkdownExtended: Downloading dependency Chromium (${pg}%)`,
                increment: pg - lastPg
            });
            lastPg = pg;
        });
    }
github hello-efficiency-inc / ridereceipts / src / renderer / services / puppeteer_download.js View on Github external
export default async function (path, cb) {
  const store = new Store()
  const fetcher = await puppeteer.createBrowserFetcher({
    path: path
  })
  const platform = await fetcher.platform()
  const latestRevision = await got(`https://storage.googleapis.com/chromium-browser-snapshots/${_.capitalize(platform)}/LAST_CHANGE`)
  const downloaded = await fetcher.download(latestRevision.body, (db, tb) => {
    const progress = _.ceil(_.divide(db, tb) * 100)
    const finished = progress === 100
    cb(progress, finished)
  })
  store.set('chromePath', downloaded.executablePath)
}
github binaryage / dirac / scripts / run_old_devtools / index.js View on Github external
async function downloadChrome(revision) {
  const fetcher = puppeteer.createBrowserFetcher();
  let progressBar = null;
  let lastDownloadedBytes = 0;
  return await fetcher.download(revision, (downloadedBytes, totalBytes) => {
    if (!progressBar) {
      const ProgressBar = require('progress');
      progressBar = new ProgressBar(`Downloading Chromium r${revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
        complete: '=',
        incomplete: ' ',
        width: 20,
        total: totalBytes,
      });
    }
    const delta = downloadedBytes - lastDownloadedBytes;
    lastDownloadedBytes = downloadedBytes;
    progressBar.tick(delta);
  });