How to use the puppeteer-extra.plugins function in puppeteer-extra

To help you get started, we’ve selected a few puppeteer-extra 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 berstend / puppeteer-extra / end-to-end-tests / basic.js View on Github external
test('will launch puppeteer with plugin support', async (t) => {
  const puppeteer = require('puppeteer-extra')
  const PuppeteerExtraPlugin = require('puppeteer-extra-plugin')
  const pluginName = 'hello-world'
  const pluginData = [ { name: 'foo', value: 'bar' } ]
  class Plugin extends PuppeteerExtraPlugin {
    constructor (opts = { }) { super(opts) }
    get name () { return pluginName }
    get data () { return pluginData }
  }
  const instance = new Plugin()
  puppeteer.use(instance)
  const browser = await puppeteer.launch({ headless: true })
  const page = await browser.newPage()

  t.is(puppeteer.plugins.length, 1)
  t.is(puppeteer.plugins[0].name, pluginName)
  t.is(puppeteer.pluginNames.length, 1)
  t.is(puppeteer.pluginNames[0], pluginName)
  t.is(puppeteer.getPluginData().length, 1)
  t.deepEqual(puppeteer.getPluginData()[0], pluginData[0])
  t.deepEqual(puppeteer.getPluginData('foo')[0], pluginData[0])
  t.is(puppeteer.getPluginData('not-existing').length, 0)

  await page.goto('http://example.com', {waitUntil: 'domcontentloaded'})
  await browser.close()
  t.true(true)
})
github berstend / puppeteer-extra / end-to-end-tests / basic.js View on Github external
const puppeteer = require('puppeteer-extra')
  const PuppeteerExtraPlugin = require('puppeteer-extra-plugin')
  const pluginName = 'hello-world'
  const pluginData = [ { name: 'foo', value: 'bar' } ]
  class Plugin extends PuppeteerExtraPlugin {
    constructor (opts = { }) { super(opts) }
    get name () { return pluginName }
    get data () { return pluginData }
  }
  const instance = new Plugin()
  puppeteer.use(instance)
  const browser = await puppeteer.launch({ headless: true })
  const page = await browser.newPage()

  t.is(puppeteer.plugins.length, 1)
  t.is(puppeteer.plugins[0].name, pluginName)
  t.is(puppeteer.pluginNames.length, 1)
  t.is(puppeteer.pluginNames[0], pluginName)
  t.is(puppeteer.getPluginData().length, 1)
  t.deepEqual(puppeteer.getPluginData()[0], pluginData[0])
  t.deepEqual(puppeteer.getPluginData('foo')[0], pluginData[0])
  t.is(puppeteer.getPluginData('not-existing').length, 0)

  await page.goto('http://example.com', {waitUntil: 'domcontentloaded'})
  await browser.close()
  t.true(true)
})

puppeteer-extra

Teach puppeteer new tricks through plugins.

MIT
Latest version published 2 years ago

Package Health Score

61 / 100
Full package analysis