Skip to content

Commit

Permalink
serverless with puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Deshmukh authored and Jay Deshmukh committed Dec 22, 2018
1 parent 6da1bcc commit d16249e
Show file tree
Hide file tree
Showing 10 changed files with 2,352 additions and 583 deletions.
6 changes: 6 additions & 0 deletions aws-node-puppeteer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
17 changes: 17 additions & 0 deletions aws-node-puppeteer/chrome-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const launchChrome = require('@serverless-chrome/lambda');
const request = require('superagent');

module.exports.getChrome = async () => {
const chrome = await launchChrome();

const response = await request
.get(`${chrome.url}/json/version`)
.set('Content-Type', 'application/json');

const endpoint = response.body.webSocketDebuggerUrl;

return {
endpoint,
instance: chrome,
};
};
19 changes: 19 additions & 0 deletions aws-node-puppeteer/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const puppeteer = require('puppeteer');
const { getChrome } = require('./chrome-script');

module.exports.hello = async (event) => {
const { url } = event.queryStringParameters;
const chrome = await getChrome();
const browser = await puppeteer.connect({
browserWSEndpoint: chrome.endpoint,
});
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle0' });
const content = await page.evaluate(() => document.body.innerHTML);
return {
statusCode: 200,
body: JSON.stringify({
content,
}),
};
};
Binary file added aws-node-puppeteer/images/aws_limits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d16249e

Please sign in to comment.