How to use puppeteer - 10 common examples

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 flow-typed / flow-typed / definitions / npm / puppeteer_v1.20.x / flow_v0.76.x-v0.103.x / test_puppeteer_v1.20.x_connect.js View on Github external
it('should complain if an option arg key is of the wrong type', () => {
    // $ExpectError string is incompatible with boolean in property `ignoreHTTPSErrors`
    puppeteer.connect({ ignoreHTTPSErrors: 'testing...' });
  });
  it('should preserve Browser type', () => {
github flow-typed / flow-typed / definitions / npm / puppeteer_v1.2.x / flow_v0.76.x- / test_puppeteer_v1.2.x_defaultArgs.js View on Github external
it('should complain if passed args', () => {
    // $ExpectError no arguments are expected by function type
    (defaultArgs('testing...'): Array);
  });
});
github flow-typed / flow-typed / definitions / npm / puppeteer_v1.20.x / flow_v0.104.x- / test_puppeteer_v1.20.x_defaultArgs.js View on Github external
it('should complain if passed args', () => {
    // $ExpectError no arguments are expected by function type
    (puppeteer.defaultArgs('testing...'): Array);
  });
});
github NationalBankBelgium / stark / packages / stark-testing / karma.conf.ci.js View on Github external
// Helpers
const helpers = require("./helpers");
const IstanbulInstrumenter = require("./istanbul-instrumenter");

// Puppeteer: https://github.com/GoogleChrome/puppeteer/
// takes care of download Chrome and making it available (can do much more :p)
process.env.CHROME_BIN = require("puppeteer").executablePath();

const rawKarmaConfig = {
	// base path that will be used to resolve all patterns (e.g. files, exclude)
	basePath: "",

	// frameworks to use
	// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
	frameworks: ["jasmine", "karma-typescript"],

	// list of files / patterns to load in the browser
	files: [
		{ pattern: helpers.root(helpers.getAngularCliAppConfig().architect.test.options.main) },
		{ pattern: helpers.root("src/**/*.ts") },
		{ pattern: helpers.root("src/**/*.html") }
	],
github mickdekkers / vue-howler / test / karma.conf.js View on Github external
const _ = require('lodash')
const babelConfig = JSON.parse(
  require('fs').readFileSync(`${__dirname}/../.babelrc`)
)

/**
 * Headless Chrome setup
 */
const ChromiumRevision = require('puppeteer/package.json').puppeteer
  .chromium_revision
const Downloader = require('puppeteer/utils/ChromiumDownloader')
const revisionInfo = Downloader.revisionInfo(
  Downloader.currentPlatform(),
  ChromiumRevision
)

process.env.CHROMIUM_BIN = revisionInfo.executablePath

/**
 * Karma config
 */
module.exports = function(config) {
  config.set({
    // browsers: ['ChromiumHeadless'],
    browsers: ['Chrome'],
github mickdekkers / vue-howler / test / karma.conf.js View on Github external
const _ = require('lodash')
const babelConfig = JSON.parse(
  require('fs').readFileSync(`${__dirname}/../.babelrc`)
)

/**
 * Headless Chrome setup
 */
const ChromiumRevision = require('puppeteer/package.json').puppeteer
  .chromium_revision
const Downloader = require('puppeteer/utils/ChromiumDownloader')
const revisionInfo = Downloader.revisionInfo(
  Downloader.currentPlatform(),
  ChromiumRevision
)

process.env.CHROMIUM_BIN = revisionInfo.executablePath

/**
 * Karma config
 */
module.exports = function(config) {
  config.set({
    // browsers: ['ChromiumHeadless'],
    browsers: ['Chrome'],

    frameworks: ['mocha'],

    // this is the entry file for all our tests.
github mickdekkers / vue-howler / test / karma.conf.js View on Github external
const _ = require('lodash')
const babelConfig = JSON.parse(
  require('fs').readFileSync(`${__dirname}/../.babelrc`)
)

/**
 * Headless Chrome setup
 */
const ChromiumRevision = require('puppeteer/package.json').puppeteer
  .chromium_revision
const Downloader = require('puppeteer/utils/ChromiumDownloader')
const revisionInfo = Downloader.revisionInfo(
  Downloader.currentPlatform(),
  ChromiumRevision
)

process.env.CHROMIUM_BIN = revisionInfo.executablePath

/**
 * Karma config
 */
module.exports = function(config) {
  config.set({
    // browsers: ['ChromiumHeadless'],
    browsers: ['Chrome'],

    frameworks: ['mocha'],
github puppeteer / examples / hash_navigation.js View on Github external
async function main() {
  const browser = await puppeteer.launch();

  const page = await browser.newPage();

  // Catch + "forward" hashchange events from page to node puppeteer.
  await page.exposeFunction('onHashChange', url => page.emit('hashchange', url));
  await page.evaluateOnNewDocument(() => {
    addEventListener('hashchange', e => onHashChange(location.href));
  });

  // Listen for hashchange events in node Puppeteer code.
  page.on('hashchange', url => console.log('hashchange event:', new URL(url).hash));

  await page.goto(url);
  await page.waitForSelector('[data-page="#page1"]'); // wait for view 1 to be "loaded".
  await printVisibleView(page);
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}`)
)();