Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"presets": [
["env", {
"targets": {
"node": "6.10"
"node": "8.10"
}
}]
]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "./node_modules/.bin/eslint src"
},
"dependencies": {
"puppeteer": "^1.1.1",
"puppeteer": "=1.3.0",
"tar": "^4.0.1"
},
"devDependencies": {
Expand Down
26 changes: 15 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
const setup = require('./starter-kit/setup');

exports.handler = async (event, context, callback) => {
// For keeping the browser launch
context.callbackWaitsForEmptyEventLoop = false;
// this handler signature requires AWS Lambda Nodejs v8.1
exports.handler = async (event, context) => {
const browser = await setup.getBrowser();
try {
const result = await exports.run(browser);
callback(null, result);
} catch (e) {
callback(e);
}

return await exports.run(browser);
};

exports.run = async (browser) => {
Expand All @@ -21,15 +16,24 @@ exports.run = async (browser) => {
);
console.log((await page.content()).slice(0, 500));

await page.type('#lst-ib', 'aaaaa');
await page.type('input[name=q]', 'aaaaa');
// avoid to timeout waitForNavigation() after click()
await Promise.all([
// avoid to
// 'Cannot find context with specified id undefined' for localStorage
page.waitForNavigation(),
page.click('[name=btnK]'),

// puppeteer v1.3.0 seems to have a problem with SVG buttons
// when using page.click() it errors with ""
// see: https://github.com/GoogleChrome/puppeteer/issues/2977
// a workaround is to execute the click in the browser
//
// page.click("input[name=btnK]"),
page.evaluate(() => document.querySelector('input[name=btnK]').click()),
]);

console.log(`page url after search: ${page.url()}`);

/* screenshot
await page.screenshot({path: '/tmp/screenshot.png'});
const aws = require('aws-sdk');
Expand Down