sambaiz / puppeteer-lambda-starter-kit

Starter Kit for running Headless-Chrome by Puppeteer on AWS Lambda.
MIT License
580 stars 82 forks source link

Stops on page.goto of exports.run without error #32

Closed dhill-ss closed 6 years ago

dhill-ss commented 6 years ago

Has anyone else seen this start fine, run without error and then stop in the middle of the exports.run. If I modify the example code as follows:

exports.run = async (browser) => {
  console.log('in exports.run..');
  const page = await browser.newPage();
  await page.goto('https://www.google.co.jp',
   {waitUntil: ['domcontentloaded', 'networkidle0']}
  );
  console.log('after goto..');
  console.log((await page.content()).slice(0, 500));

I get the first console.log and not the second...

START RequestId: 07699f81-73fe-11e8-8b00-6f64b92f92ad Version: $LATEST
2018-06-19T20:19:16.966Z    07699f81-73fe-11e8-8b00-6f64b92f92ad    calling exports.run..
2018-06-19T20:19:16.967Z    07699f81-73fe-11e8-8b00-6f64b92f92ad    in exports.run..
END RequestId: 07699f81-73fe-11e8-8b00-6f64b92f92ad
REPORT RequestId: 07699f81-73fe-11e8-8b00-6f64b92f92ad  Duration: 4174.92 ms    Billed Duration: 4200 ms    Memory Size: 1024 MB    Max Memory Used: 280 MB 

Any ideas?

dhill-ss commented 6 years ago

The timeout is set to 3 minutes. My entire index.js is:

const setup = require('./starter-kit/setup');

exports.handler = async (event, context, callback) => {
  // For keeping the browser launch
  context.callbackWaitsForEmptyEventLoop = false;
  const browser = await setup.getBrowser();
  console.log('calling exports.run..');
  exports.run(browser).then(
    (result) => callback(null, result)
  ).catch(
    (err) => callback(err)
  );
};

exports.run = async (browser) => {
  console.log('in exports.run..');
  const page = await browser.newPage();
  await page.goto('https://www.google.co.jp',
   {waitUntil: ['domcontentloaded', 'networkidle0']}
  );
  console.log('after goto..');
  console.log((await page.content()).slice(0, 500));
  await page.screenshot({path: '/tmp/screenshots/google.png'});
  console.log('after screenshot..');
  await page.close();
  return 'done';
};
dhill-ss commented 6 years ago

Note: I found that when I set the Runtime to "Node.js 6.10" in the Function code area of the Lambda Configuration, it passes the part where it exited without error. Perhaps update the Documentation to include this step.