shawnliujw / puppeteer-lambda

Module for using Headless-Chrome by Puppeteer on AWS Lambda.
MIT License
117 stars 20 forks source link

i got error on page.title #17

Closed muners closed 5 years ago

muners commented 5 years ago

thanks your library.

when i try, i got this error. do you have any idea?

code on lamda


exports.handler = async (event) => {
    const puppeteerLambda = require('puppeteer-lambda');
    const browser = await puppeteerLambda.getBrowser({
    headless: true
    });
    const page = await browser.newPage();
    await page.goto('https://www.yahoo.co.jp');
    let title = await page.title;

    await browser.close(); 

    // TODO implement
    const response = {
        statusCode: 200,
        body: JSON.stringify(`hello ${title}`),
    };
    return response;
};

response

{
  "statusCode": 200,
  "body": "\"hello function (...args) {\\n        const syncStack = new Error();\\n        return method.call(this, ...args).catch(e => {\\n          const stack = syncStack.stack.substring(syncStack.stack.indexOf('\\\\n') + 1);\\n          const clientStack = stack.substring(stack.indexOf('\\\\n'));\\n          if (!e.stack.includes(clientStack))\\n            e.stack += '\\\\n  -- ASYNC --\\\\n' + stack;\\n          throw e;\\n        });\\n      }\""
}

log

START RequestId: 621187f0-e6f0-4508-b3dd-75028fd1a93d Version: $LATEST
2019-03-02T00:32:51.136Z    621187f0-e6f0-4508-b3dd-75028fd1a93d    Launch chrome: HeadlessChrome/69.0.3497.81
2019-03-02T00:32:52.738Z    621187f0-e6f0-4508-b3dd-75028fd1a93d    ******************************************************************************************************************************  
2019-03-02T00:32:52.739Z    621187f0-e6f0-4508-b3dd-75028fd1a93d    Suggest not to close browser in Lambda ENV, if close it , the Browser object is considered disposed and cannot be used anymore. 
2019-03-02T00:32:52.739Z    621187f0-e6f0-4508-b3dd-75028fd1a93d    ******************************************************************************************************************************  
END RequestId: 621187f0-e6f0-4508-b3dd-75028fd1a93d
REPORT RequestId: 621187f0-e6f0-4508-b3dd-75028fd1a93d  Duration: 7945.49 ms    Billed Duration: 8000 ms    Memory Size: 768 MB Max Memory Used: 433 MB 

i set env

CUSTOM_CHROME true
shawnliujw commented 5 years ago

@muners seems due to your response body issue , have u tried console.log the response and see whether it's correctly ?