How to use chrome-aws-lambda - 10 common examples

To help you get started, we’ve selected a few chrome-aws-lambda 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 cheeaun / puppetron / index.js View on Github external
let actionDone = false;
    const width = parseInt(searchParams.get('width'), 10) || 1024;
    const height = parseInt(searchParams.get('height'), 10) || 768;

    page = cache.get(pageURL);
    if (!page) {
      if (!browser) {
        console.log('🚀 Launch browser!');
        const config = {
          ...(isDev ? {
            // executablePath: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
            executablePath: findChrome(),
          } : {
            args: chrome.args,
            executablePath: await chrome.executablePath,
            headless: chrome.headless,
          }),
        };
        browser = await puppeteer.launch(config);
      }
      page = await browser.newPage();

      const nowTime = +new Date();
      let reqCount = 0;
      await page.setRequestInterception(true);
      page.on('request', (request) => {
        const url = request.url();
        const method = request.method();
        const resourceType = request.resourceType();

        // Skip data URIs
        if (/^data:/i.test(url)){
github netlify-labs / netlify-functions-headless-chrome / functions / chrome / chrome.js View on Github external
exports.handler = async (event, context, callback) => {
  let theTitle = null
  let browser = null
  console.log('spawning chrome headless')
  try {
    const executablePath = await chromium.executablePath

    // setup
    browser = await puppeteer.launch({
      args: chromium.args,
      executablePath: executablePath,
      headless: chromium.headless,
    })

    // Do stuff with headless chrome
    const page = await browser.newPage()
    const targetUrl = 'https://davidwells.io'

    // Goto page and then do stuff
    await page.goto(targetUrl, {
      waitUntil: ["domcontentloaded", "networkidle0"]
    })
github cheeaun / puppetron / index.js View on Github external
let actionDone = false;
    const width = parseInt(searchParams.get('width'), 10) || 1024;
    const height = parseInt(searchParams.get('height'), 10) || 768;

    page = cache.get(pageURL);
    if (!page) {
      if (!browser) {
        console.log('🚀 Launch browser!');
        const config = {
          ...(isDev ? {
            // executablePath: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
            executablePath: findChrome(),
          } : {
            args: chrome.args,
            executablePath: await chrome.executablePath,
            headless: chrome.headless,
          }),
        };
        browser = await puppeteer.launch(config);
      }
      page = await browser.newPage();

      const nowTime = +new Date();
      let reqCount = 0;
      await page.setRequestInterception(true);
      page.on('request', (request) => {
        const url = request.url();
        const method = request.method();
        const resourceType = request.resourceType();

        // Skip data URIs
github netlify-labs / netlify-functions-headless-chrome / functions / chrome / chrome.js View on Github external
exports.handler = async (event, context, callback) => {
  let theTitle = null
  let browser = null
  console.log('spawning chrome headless')
  try {
    const executablePath = await chromium.executablePath

    // setup
    browser = await puppeteer.launch({
      args: chromium.args,
      executablePath: executablePath,
      headless: chromium.headless,
    })

    // Do stuff with headless chrome
    const page = await browser.newPage()
    const targetUrl = 'https://davidwells.io'

    // Goto page and then do stuff
    await page.goto(targetUrl, {
      waitUntil: ["domcontentloaded", "networkidle0"]
    })

    await page.waitForSelector('#phenomic')

    theTitle = await page.title();

    console.log('done on page', theTitle)
github tensult / cloud-reports / src / reporters / pdf / index.ts View on Github external
const getPuppeteer = async () => {
    try {
        const puppeteer = require('puppeteer');
        return await puppeteer.launch();
    } catch (error) {
        if (error.code === 'MODULE_NOT_FOUND') {
            console.log('Error(This package is used for local development) ', JSON.stringify(error, null, 2));
            try {
                const chromium = require('chrome-aws-lambda')
                return await chromium.puppeteer.launch({
                    args: chromium.args,
                    defaultViewport: chromium.defaultViewport,
                    executablePath: await chromium.executablePath,
                    headless: chromium.headless
                });
            } catch (_error) {
                throw error;
            }
        }
    }
}
github tensult / cloud-reports / src / reporters / pdf / index.ts View on Github external
const getPuppeteer = async () => {
    try {
        const puppeteer = require('puppeteer');
        return await puppeteer.launch();
    } catch (error) {
        if (error.code === 'MODULE_NOT_FOUND') {
            console.log('Error(This package is used for local development) ', JSON.stringify(error, null, 2));
            try {
                const chromium = require('chrome-aws-lambda')
                return await chromium.puppeteer.launch({
                    args: chromium.args,
                    defaultViewport: chromium.defaultViewport,
                    executablePath: await chromium.executablePath,
                    headless: chromium.headless
                });
            } catch (_error) {
                throw error;
            }
        }
    }
}
github tensult / cloud-reports / src / reporters / pdf / index.ts View on Github external
const getPuppeteer = async () => {
    try {
        const puppeteer = require('puppeteer');
        return await puppeteer.launch();
    } catch (error) {
        if (error.code === 'MODULE_NOT_FOUND') {
            console.log('Error(This package is used for local development) ', JSON.stringify(error, null, 2));
            try {
                const chromium = require('chrome-aws-lambda')
                return await chromium.puppeteer.launch({
                    args: chromium.args,
                    defaultViewport: chromium.defaultViewport,
                    executablePath: await chromium.executablePath,
                    headless: chromium.headless
                });
            } catch (_error) {
                throw error;
            }
        }
    }
}
github tensult / cloud-reports / src / reporters / pdf / index.ts View on Github external
const getPuppeteer = async () => {
    try {
        const puppeteer = require('puppeteer');
        return await puppeteer.launch();
    } catch (error) {
        if (error.code === 'MODULE_NOT_FOUND') {
            console.log('Error(This package is used for local development) ', JSON.stringify(error, null, 2));
            try {
                const chromium = require('chrome-aws-lambda')
                return await chromium.puppeteer.launch({
                    args: chromium.args,
                    defaultViewport: chromium.defaultViewport,
                    executablePath: await chromium.executablePath,
                    headless: chromium.headless
                });
            } catch (_error) {
                throw error;
            }
        }
    }
}
github zeit / og-image / api / _lib / options.ts View on Github external
export async function getOptions(isDev: boolean) {
    let options: Options;
    if (isDev) {
        options = {
            args: [],
            executablePath: exePath,
            headless: true
        };
    } else {
        options = {
            args: chrome.args,
            executablePath: await chrome.executablePath,
            headless: chrome.headless,
        };
    }
    return options;
}
github styfle / screenshot-v2 / chromium.js View on Github external
async function getScreenshot(url, type, quality, fullPage) {
    const browser = await puppeteer.launch({
        args: chrome.args,
        executablePath: await chrome.executablePath,
        headless: chrome.headless,
    });

    const page = await browser.newPage();
    await page.goto(url);
    const file = await page.screenshot({ type,  quality, fullPage });
    await browser.close();
    return file;
}

chrome-aws-lambda

Chromium Binary for AWS Lambda and Google Cloud Functions

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis