• Stars
    star
    727
  • Rank 62,062 (Top 2 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 7 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run Puppeteer code in the cloud

Try Puppeteer!

Run Puppeteer scripts in the cloud.

Try it: https://try-puppeteer.appspot.com

Develop

Installation:

yarn; yarn install-backend
# or npm i

Backend

The backend is a Docker container which installs the latest Chrome package that works with Puppeteer on Linux.

Note: You'll need to have Docker running before attempting each step in this section.

Building it

yarn build

Running the container

The container can be run in two modes: standalone as an executable, or as a web service.

1. Using the standalone CLI

The first is a "standalone" mode that runs a Puppeteer script from the CLI. It takes a script file as an argument and runs it in the container.

./backend/run_puppeteer.sh your-puppeteer-script.js

2. Running the web service

The second option is running the container as a web server. The endpoint accepts file uploads for running your Puppeteer scripts in the cloud:

Start the server:

cd backend
yarn serve
# yarn restart is handy too. It rebuilds the container and starts the server.

Example - running a Puppeteer script

async function runCode(code) {
  const form = new FormData();
  form.append('file', new Blob([code], {type: 'text/javascript'}));
  const resp = await fetch('http://localhost:8080/run', {method: 'POST', body: form});
  return await resp.json();
}

const code = `
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  console.log(await page.content());
  browser.close();
`;

runCode(code).then(result => {
  if (result.errors) {
    console.error(result.errors);
  }
  console.log(result.log);
});

Notes:

  • There's no need to require('puppeteer'). This is done for you on the backend.
  • Top-level async/await are supported.

Code editor frontend

Fire up the code editor UI from the main directory:

yarn serve

Then navigate to http://localhost:8081.

Deployment

  1. Update the version of Puppeteer used in index.html, include the doc link. TODO: make this automatic.

  2. yarn deploy deploys both the frontend and backend services to App Engine Flex. The apps can also be deployed individually:

yarn deploy-frontend
yarn deploy-backend

Notes & Limitations

  • By default, Puppeteer launches and uses its own bundled version of Chromium. To use the google-chrome-unstable installed by the container, pass executablePath:

    const browser = await puppeteer.launch({
      executablePath: 'google-chrome-unstable'
    });

More Repositories

1

filer.js

A wrapper library for the HTML5 Filesystem API what reuses UNIX commands (cp, mv, ls) for its API.
JavaScript
1,486
star
2

appmetrics.js

A small (< 1kb) library for measuring things in your web app and reporting the results to Google Analytics.
JavaScript
1,370
star
3

polymer-gmail

Polymer 1.0 version of New Gmail app
HTML
526
star
4

idb.filesystem.js

HTML5 Filesystem API polyfill using IndexedDB
JavaScript
486
star
5

html5demos

HTML5 Demos
JavaScript
384
star
6

material-playground

Polymer material design playground
JavaScript
258
star
7

html5can

My "The Web Can Do That!?" presentation from Google I/O 2012
CSS
216
star
8

demos

HTML
146
star
9

lighthouse-badge

Lighthouse score badge
HTML
136
star
10

polymer-experiments

Example/useful Polymer elements
HTML
104
star
11

geo-location

Web component element for the Geolocation API
HTML
86
star
12

puppeteer-functions

Puppeteer Firebase Functions demo
JavaScript
79
star
13

polymer-change

Google I/O 2014 session
CSS
66
star
14

i18n-msg

Polymer element for i18n string replacement
HTML
63
star
15

headless-karma-travis

Example repo for testing on Headless Chrome with Travis + Karma + Mocha + Chai
JavaScript
44
star
16

declarative-web-components

Author web components, declaratively
JavaScript
35
star
17

lighthouse-hue

Big Lighthouse Kiosk at Google I/O 2017
JavaScript
29
star
18

webcomponentsshift

Web Components: A Tectonic Shift for Web Development
CSS
28
star
19

polymer-todomvc-codelab

Codelab for Polymer-based TodoMVC app
CSS
20
star
20

icanbeyourlighthouse

When you need guidance
HTML
14
star
21

webcomponents

Resources for Web Components
13
star
22

spark-line

<spark-line> web component for making...spark lines!
JavaScript
11
star
23

lighthouse-httparchive

Lighthouse metrics from HTTPArchive snapshots
JavaScript
8
star
24

io-2012-slides

Automatically exported from code.google.com/p/io-2012-slides
CSS
7
star
25

beacon-send

Web component for the Beacon API
HTML
7
star
26

wedding-site

HTML
7
star
27

oauthplayground

The original OAuth (1.0) Playground
PHP
7
star
28

moreawesomeweb

A More Awesome Web: Features You've Always Wanted @ Google I/O 2013
CSS
7
star
29

html5wow

Automatically exported from code.google.com/p/html5wow
JavaScript
5
star
30

Gauntlet

Gauntlet card game
5
star
31

featurepolicy-extension

Feature Policy Tester DevTools Extension
JavaScript
4
star
32

blink-components

web service that lists the components used by the Blink team
HTML
4
star
33

blog

My Blog
HTML
4
star
34

select-y

Clippy like helper
CSS
4
star
35

strum

3
star
36

github-quarterly-stats

Adds a button on a user's Github landing page to fetch contributions for the quarter
JavaScript
3
star
37

site-template

Static, Node/Express server setup
JavaScript
2
star
38

dotfiles

Resources
Shell
2
star