phantomimi

1.0.0 • Public • Published

phantomimi

Drive Chrome headless on AWS LAMBDA

npm

Contents

  1. [General purpose](#general purpose)
  2. Installation
  3. Setup
  4. [Local Development](#local development)
  5. Api available

General purpose

This lib has been built for web scraping and automation. We add a lot of js librairies (like Jquery and others) to look like a human when scraping or automating task.

Installation

Install with npm:

npm install --save phantomimi

Setup

Use in your AWS Lambda function. Requires Node 6.10.

let chromeHelper = require("phantomimi")

module.exports.handler = function handler (event, context, callback) {
  // Chrome proxy configuration
  const proxyConfiguration = {
    host:'XX.XX.XX.XXX',
    port:'YYYYY',
    username:'username',
    password:'passwordhere'
  }

  // Chrome config
  const chromeConfig = {
    userAgent:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
    proxyConfiguration,
    debugRequest:true,
    viewPort:{width:1920,height:1080}
  }

  let result = await myChrome.launch()
  if(!result.statut){
    // Error while launching chrome instance
    console.log(result.message)
    return false
  }

  await myChrome.open('https://google.com')
  /* 
    Do what you want here 
  */
  
  await myChrome.close()
}

Local Development

Local development is supported. In a non-lambda environment, the package will use chrome-launcher to launch a locally installed Chrome. You can also pass your own CHROME_PATH:

  // Chrome config
  const chromeConfig = {
    userAgent:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
    proxyConfiguration,
    debugRequest:true,
    CHROME_PATH:'/my/local/chrome/path',
    viewPort:{width:1920,height:1080}
  }

Api available

Caution: We test and develop features against the beta channel. We know it can lead to unexpected results, especially in relation to the Chrome DevTools Protocol (which is used by tools like Chromeless and Puppeteer).

Readme

Keywords

none

Package Sidebar

Install

npm i phantomimi

Weekly Downloads

2

Version

1.0.0

License

ISC

Last publish

Collaborators

  • hackstudio