How to use the chrome-aws-lambda.headless function in chrome-aws-lambda

To help you get started, we’ve selected a few chrome-aws-lambda examples, based on popular ways it is used in public projects.

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"]
    })

    await page.waitForSelector('#phenomic')

    theTitle = await page.title();

    console.log('done on page', theTitle)
github sthobis / site-palette / api / get-palette.js View on Github external
const getOptions = async () => {
  return process.env.NOW_REGION === "dev1"
    ? {
        args: [],
        executablePath: exePath,
        headless: true,
    }
    : {
      args: chrome.args,
      executablePath: await chrome.executablePath,
      headless: chrome.headless
    }
}
github ireade / netlify-puppeteer-screenshot-demo / functions / take-screenshot / take-screenshot.js View on Github external
exports.handler = async (event, context) => {

    const pageToScreenshot = JSON.parse(event.body).pageToScreenshot;

    if (!pageToScreenshot) return {
        statusCode: 400,
        body: JSON.stringify({ message: 'Page URL not defined' })
    }

    const browser = await chromium.puppeteer.launch({
        args: chromium.args,
        defaultViewport: chromium.defaultViewport,
        executablePath: await chromium.executablePath,
        headless: chromium.headless,
    });
    
    const page = await browser.newPage();

    await page.goto(pageToScreenshot, { waitUntil: 'networkidle2' });

    const screenshot = await page.screenshot({ encoding: 'binary' });

    await browser.close();
  
    return {
        statusCode: 200,
        body: JSON.stringify({ 
            message: `Complete screenshot of ${pageToScreenshot}`, 
            buffer: screenshot 
        })
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 tophat / sanity-runner / service / src / jestSetup / puppeteer / setup.js View on Github external
module.exports = async () => {
    const config = {
        args: chromium.args,
        defaultViewport: chromium.defaultViewport,
        executablePath: await chromium.executablePath,
        headless: chromium.headless,
    }
    const browser = await chromium.puppeteer.launch(config)
    global.__BROWSER__ = browser
    await fs.mkdirs(DIR)
    await fs.writeFile(path.join(DIR, 'wsEndpoint'), browser.wsEndpoint())
}
github faastjs / examples / aws-puppeteer-ts / functions.ts View on Github external
export async function runPuppeteer(url: string) {
    const browser = await puppeteer.launch({
        args: chromium.args,
        defaultViewport: chromium.defaultViewport,
        executablePath: await chromium.executablePath,
        headless: chromium.headless
    });
    try {
        let page = await browser.newPage();
        await page.goto(url);
        const title = await page.title();
        const screenshot = await page.screenshot({ encoding: "binary" });
        return { title, screenshot };
    } finally {
        if (browser !== null) {
            await browser.close();
        }
    }
}
github TimoSta / sprite / packages / api / util / screenshot.ts View on Github external
const getScreenshot = async (pageContent: string, targetId: string) => {
  const browser = await puppeteer.launch({
    args: chrome.args,
    executablePath: await chrome.executablePath,
    headless: chrome.headless
  })

  const page = await browser.newPage()
  await page.setContent(pageContent)

  const rect = await page.evaluate(targetId => {
    const element = document.getElementById(targetId)
    const {x, y, width, height} = element.getBoundingClientRect() as DOMRect
    return {left: x, top: y, width, height, id: element.id}
  }, targetId)

  const file = await page.screenshot({
    type: 'png',
    omitBackground: true,
    clip: {
      x: rect.left - padding,
github bartveneman / extract-css / _chromium.js View on Github external
async function getOptions() {
	if (isDev) {
		return {
			args: [],
			executablePath: exePath,
			headless: true
		}
	}

	return {
		args: chrome.args,
		executablePath: await chrome.executablePath,
		headless: chrome.headless
	}
}
github premieroctet / screen-guru / lambda / screenshot / handler.js View on Github external
module.exports.screenshot = async (event, context, callback) => {
  let browser = null;

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

    let page = await browser.newPage();

    let url = 'https://www.premieroctet.com/';
    let color = 'transparent';

    if (event.queryStringParameters && event.queryStringParameters.url) {
      url = decodeURIComponent(event.queryStringParameters.url);
      url = url.toLowerCase();

      if (!url.startsWith('http')) {
        url = 'http://' + url;
      }
    }

chrome-aws-lambda

Chromium Binary for AWS Lambda and Google Cloud Functions

MIT
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis