forked from serverless/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jay Deshmukh
authored and
Jay Deshmukh
committed
Dec 22, 2018
1 parent
6da1bcc
commit d16249e
Showing
10 changed files
with
2,352 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# package directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Serverless directories | ||
.serverless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
}; | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.