Skip to content

Commit 12a6e18

Browse files
authored
Merge pull request #21 from sambaiz/v1.1.1_1
puppeteer v1.1.1 and add sample
2 parents 11febb2 + e302d0f commit 12a6e18

File tree

7 files changed

+55
-7
lines changed

7 files changed

+55
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Run `npm run package-nochrome`, deploy the package.zip, and set following env va
5656
This kit includes Chrome built by myself because official build Chrome installed by Puppeteer has problems about running on Lambda (missing shared library etc.).
5757

5858
If you want to use latest chrome, run chrome/buildChrome.sh on EC2 having at least 16GB memory and 30GB volume.
59-
See also [serverless-chrome](https://github.com/adieuadieu/serverless-chrome/blob/master/chrome/README.md).
59+
See also [serverless-chrome](https://github.com/adieuadieu/serverless-chrome/blob/master/docs/chrome.md).
6060
Once you build it, link to `headless_shell.tar.gz` in `chrome` dir.
6161

6262
## Article
44.4 MB
Binary file not shown.

chrome/headless_shell.tar.gz

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
HeadlessChrome-63.0.3213.0.tar.gz
1+
headless_shell-67.0.3361.0.tar.gz

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "./node_modules/.bin/eslint src"
1212
},
1313
"dependencies": {
14-
"puppeteer": "^0.10.2",
14+
"puppeteer": "^1.1.1",
1515
"tar": "^4.0.1"
1616
},
1717
"devDependencies": {

serverless.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ provider:
55
runtime: nodejs6.10
66
memorySize: 1536
77
timeout: 180
8+
# if needed (e.g. upload snapshot)
9+
# iamRoleStatements:
10+
# - Effect: "Allow"
11+
# Action:
12+
# - "s3:PutObject"
13+
# Resource: "arn:aws:s3:::<bucket name>/*"
814

915
functions:
1016
test-function:
1117
handler: index.handler
18+
environment:
19+
DEBUG: 0
1220

1321
package:
1422
artifact: ./package.zip

src/index.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,48 @@ exports.handler = async (event, context, callback) => {
1212
};
1313

1414
exports.run = async (browser) => {
15+
// implement here
16+
// this is sample
1517
const page = await browser.newPage();
16-
await page.goto('https://www.google.co.jp');
18+
await page.goto('https://www.google.co.jp',
19+
{waitUntil: ['domcontentloaded', 'networkidle0']}
20+
);
21+
console.log((await page.content()).slice(0, 500));
22+
23+
await page.type('#lst-ib', 'aaaaa');
24+
// avoid to timeout waitForNavigation() after click()
25+
await Promise.all([
26+
// avoid to
27+
// 'Cannot find context with specified id undefined' for localStorage
28+
page.waitForNavigation(),
29+
page.click('[name=btnK]'),
30+
]);
31+
32+
/* screenshot
33+
await page.screenshot({path: '/tmp/screenshot.png'});
34+
const aws = require('aws-sdk');
35+
const s3 = new aws.S3({apiVersion: '2006-03-01'});
36+
const fs = require('fs');
37+
const screenshot = await new Promise((resolve, reject) => {
38+
fs.readFile('/tmp/screenshot.png', (err, data) => {
39+
if (err) return reject(err);
40+
resolve(data);
41+
});
42+
});
43+
await s3.putObject({
44+
Bucket: '<bucket name>',
45+
Key: 'screenshot.png',
46+
Body: screenshot,
47+
}).promise();
48+
*/
49+
50+
// cookie and localStorage
51+
await page.setCookie({name: 'name', value: 'cookieValue'});
52+
console.log(await page.cookies());
53+
console.log(await page.evaluate(() => {
54+
localStorage.setItem('name', 'localStorageValue');
55+
return localStorage.getItem('name');
56+
}));
1757
await page.close();
1858
return 'done';
1959
};

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,9 +1848,9 @@ punycode@^1.4.1:
18481848
version "1.4.1"
18491849
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
18501850

1851-
puppeteer@^0.10.2:
1852-
version "0.10.2"
1853-
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-0.10.2.tgz#b4a959a722bf626ca481f2aeba11fdb810f2c98f"
1851+
puppeteer@^1.1.1:
1852+
version "1.1.1"
1853+
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-1.1.1.tgz#adbf25e49f5ef03443c10ab8e09a954ca0c7bfee"
18541854
dependencies:
18551855
debug "^2.6.8"
18561856
extract-zip "^1.6.5"

0 commit comments

Comments
 (0)