From 7a19420ff87b449ba0b094ba54fcbd95def17a84 Mon Sep 17 00:00:00 2001 From: Mark Glasgow Date: Mon, 1 Apr 2019 11:40:36 +1100 Subject: [PATCH 1/3] fix puppeteer version to v1.3.0, to match the bundled headless chrome v67 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 41ab805..d4b72f8 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "lint": "./node_modules/.bin/eslint src" }, "dependencies": { - "puppeteer": "^1.1.1", + "puppeteer": "=1.3.0", "tar": "^4.0.1" }, "devDependencies": { From 4968540e19cb0da1986318b447a6d189da4aaefd Mon Sep 17 00:00:00 2001 From: Mark Glasgow Date: Mon, 1 Apr 2019 19:43:44 +1100 Subject: [PATCH 2/3] AWS Lambda entry point now supports nodejs v8.10 only --- .babelrc | 2 +- src/index.js | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.babelrc b/.babelrc index 2f7f20c..20fb9dd 100644 --- a/.babelrc +++ b/.babelrc @@ -2,7 +2,7 @@ "presets": [ ["env", { "targets": { - "node": "6.10" + "node": "8.10" } }] ] diff --git a/src/index.js b/src/index.js index d77ebe1..ef85d3e 100755 --- a/src/index.js +++ b/src/index.js @@ -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) => { From 9a5f0ecb503e3476722ee71adce11f2ac5e705a9 Mon Sep 17 00:00:00 2001 From: Mark Glasgow Date: Mon, 1 Apr 2019 19:44:00 +1100 Subject: [PATCH 3/3] fix up example after Google changed element names on their home page --- src/index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index ef85d3e..10522ef 100755 --- a/src/index.js +++ b/src/index.js @@ -16,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');