How to use the puppeteer-core.connect 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 chronotruck / vue-ctk-date-time-picker / tests / integration / puppeteer_environment.js View on Github external
async setup () {
    // eslint-disable-next-line
    console.log('Set-up puppeteer environment')

    await super.setup()
    this.global.__BROWSER__ = await puppeteer.connect({ browserWSEndpoint: 'ws://chrome:3000' })
    this.global.__BROWSER__.on('disconnected', () => {
      // eslint-disable-next-line
      console.log('Browser disconnected.')
    })
  }
github justinribeiro / lighthouse-action / src / chrome.js View on Github external
async function launchChromeAndRunLighthouse(url, opts, config) {
  // eslint-disable-next-line no-unused-vars
  const chrome = await chromeLauncher.launch({
    port: 9222,
    logLevel: 'silent',
    chromeFlags: ['--headless', '--disable-gpu'],
  });

  const browser = await puppeteer.connect({
    browserURL: 'http://localhost:9222',
  });

  browser.on('targetchanged', async target => {
    const page = await target.page();

    if (NETWORK[opts.connection]) {
      await page
        .target()
        .createCDPSession()
        .then(client => {
          console.log(
            `CDP: network conditions set to WPT ${opts.connection} profile.`,
          );
          return client.send('Network.emulateNetworkConditions', {
            offline: NETWORK[opts.connection].offline,
github hello-efficiency-inc / ridereceipts / src / renderer / services / puppeteer_lyft.js View on Github external
export default async function (email, headers, year, month, invoiceDate, html) {
  const documentDir = jetpack.cwd(store.get('invoicePath'))
  const chrome = await launch(puppeteer)
  store.set('processPID', chrome.pid) // Store process ID to kill when app quits
  const resp = await util.promisify(request)(`http://localhost:${chrome.port}/json/version`)
  const { webSocketDebuggerUrl } = JSON.parse(resp.body)
  const browser = await puppeteer.connect({
    browserWSEndpoint: webSocketDebuggerUrl
  })

  const page = await browser.newPage()
  await page.setCacheEnabled(true)
  await page.setExtraHTTPHeaders(headers)
  await page.setContent(html)
  await page.waitFor(2000)

  if (!jetpack.exists(documentDir.path(`${documentDir.path()}/${email}/Lyft/${year}/${month}/`))) {
    jetpack.dir(documentDir.path(`${documentDir.path()}/${email}/Lyft/${year}/${month}/`))
  }

  await page.emulateMedia('print')
  const receiptFilePath = `${documentDir.path()}/${email}/Lyft/${year}/${month}/Receipt-${invoiceDate}.pdf`
  await page.pdf({
github hello-efficiency-inc / ridereceipts / src / renderer / services / puppeteer_uberv2.js View on Github external
export default async function () {
  // Selectors Needed
  const EMAIL_SELECTOR = '#useridInput'
  const PASSWORD_SELECTOR = '#password'
  const SMS_SELECTOR = '#verificationCode'
  const NEXT_BUTTON = '#app-body > div > div:nth-child(1) > form > button'
  const VERIFY_BUTTON = '#app-body > div > div > form > button'
  const DASHBOARD = '#root'
  const documentDir = jetpack.cwd(store.get('invoicePath'))
  const chrome = await launch(puppeteer)
  store.set('processPID', chrome.pid) // Store process ID to kill when app quits

  const resp = await util.promisify(request)(`http://localhost:${chrome.port}/json/version`)
  const { webSocketDebuggerUrl } = JSON.parse(resp.body)
  const browser = await puppeteer.connect({
    browserWSEndpoint: webSocketDebuggerUrl
  })

  const page = await browser.newPage()

  await page.setViewport({
    width: 1440,
    height: 990,
    deviceScaleFactor: 2
  })

  await page.setCacheEnabled(true)
  await page.setJavaScriptEnabled(true)

  // Launch Page
  await page.goto('https://auth.uber.com/login?next_url=https://riders.uber.com', { waitUntil: 'domcontentloaded' })
github hello-efficiency-inc / ridereceipts / src / renderer / services / puppeteer.js View on Github external
export default async function (email, headers, year, month, invoiceDate, html, rideType) {
  const documentDir = jetpack.cwd(store.get('invoicePath'))
  const chrome = await launch(puppeteer)
  store.set('processPID', chrome.pid) // Store process ID to kill when app quits
  const resp = await util.promisify(request)(`http://localhost:${chrome.port}/json/version`)
  const { webSocketDebuggerUrl } = JSON.parse(resp.body)
  const browser = await puppeteer.connect({
    browserWSEndpoint: webSocketDebuggerUrl
  })

  const rideDirectory = rideType

  const page = await browser.newPage()
  await page.setCacheEnabled(true)
  await page.setExtraHTTPHeaders(headers)
  await page.setContent(html)
  await page.waitFor(1000)

  if (!jetpack.exists(documentDir.path(`${documentDir.path()}/${email}/${rideDirectory}/${year}/`))) {
    jetpack.dir(documentDir.path(`${documentDir.path()}/${email}/${rideDirectory}/${year}/`))
  }

  await page.emulateMedia('print')
github webhintio / hint / packages / connector-puppeteer / src / lib / lifecycle.ts View on Github external
const connectToBrowser = async (currentInfo: BrowserInfo, options: LifecycleLaunchOptions) => {
    const connectOptions = { ...currentInfo, ...options };

    const browser = await puppeteer.connect(connectOptions);

    debug(`Creating new page in existing browser`);

    const context = await browser.createIncognitoBrowserContext();
    const page = await context.newPage();

    page.setCacheEnabled(false);
    page.setDefaultTimeout(options.timeout || TIMEOUT);

    return { browser, page };
};
github onderceylan / pwa-asset-generator / src / helpers / browser.ts View on Github external
const getSystemBrowserInstance = async (
  chrome: LaunchedChrome,
  launchArgs?: LaunchOptions,
): Promise => {
  const chromeVersionInfo = await getLaunchedChromeVersionInfo(chrome);

  return puppeteer.connect({
    ...launchArgs,
    browserWSEndpoint: chromeVersionInfo.webSocketDebuggerUrl,
  });
};
github webhintio / hint / packages / connector-puppeteer / src / lib / lifecycle.ts View on Github external
launcherProcess.on('message', async (browserInfo: BrowserInfo) => {
            const finalOptions = { ...browserInfo, ...options };
            const browser = await puppeteer.connect(finalOptions);

            launcherProcess.unref();
            launcherProcess.disconnect();

            resolve(browser);
        });