Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] "Cannot read property 'launch' of undefined" #3084

Closed
osmenia opened this issue Jul 22, 2020 · 5 comments
Closed

[Question] "Cannot read property 'launch' of undefined" #3084

osmenia opened this issue Jul 22, 2020 · 5 comments

Comments

@osmenia
Copy link

osmenia commented Jul 22, 2020

Hi Team,

I am playing with AWS Lambda and Playwright.

with "playwright-aws-lambda": "^0.5.2", "playwright-core": "^1.0.1", works fine

but with "playwright-aws-lambda": "^0.5.2", "playwright-core": "^1.2.1", does not work.

what could be a problem?

my Code:

const playwright = require('playwright-aws-lambda');

exports.handler = async (event, context) => {
  let result = null;
  let browser = null;

  try {
    const browser = await playwright.launchChromium();
    const context = await browser.newContext();

    const page = await context.newPage();
    await page.goto(event.url || 'https://google.com');

    console.log('Page title: ', await page.title());
  } catch (error) {
    throw error;
  } finally {
    if (browser !== null) {
      await browser.close();
    }
  }
};

Error Message:

{
  "errorType": "TypeError",
  "errorMessage": "Cannot read property 'launch' of undefined",
  "trace": [
    "TypeError: Cannot read property 'launch' of undefined",
    "    at Object.launchChromium (/opt/node_modules/playwright-aws-lambda/dist/src/chromium.js:90:47)",
    "    at async Runtime.exports.handler (/var/task/api/poc1/handler.js:8:21)"
  ]
}

tnx a lot

@mxschmitt
Copy link
Member

It seems like its caused by that issue: #2905 since they are using playwright-core internally to launch Chromium.

https://github.com/JupiterOne/playwright-aws-lambda/blob/537234f35a59f4e54445958fb508c45431d9276c/src/chromium.ts#L102-L107

@osmenia
Copy link
Author

osmenia commented Jul 22, 2020 via email

@mxschmitt
Copy link
Member

mxschmitt commented Jul 22, 2020

I think if you add this to your package.json as a dependency it should work as a workaround:

"playwright-core": "npm:[email protected]",

@osmenia
Copy link
Author

osmenia commented Jul 23, 2020

Hi Max,

I created new layer with:

package.json

....
  "license": "ISC",
  "dependencies": {
    "playwright-aws-lambda": "^0.5.2",
    "playwright-chromium": "^1.2.1",
    "playwright-core": "npm:[email protected]"
  }
} 

Error:

{
  "errorType": "TypeError",
  "errorMessage": "Cannot read property 'launch' of undefined",
  "trace": [
    "TypeError: Cannot read property 'launch' of undefined",
    "    at Object.launchChromium (/opt/nodejs/node_modules/playwright-aws-lambda/dist/src/chromium.js:90:47)",
    "    at processTicksAndRejections (internal/process/task_queues.js:97:5)",
    "    at async Runtime.exports.handler (/var/task/index.js:8:21)"
  ]
}

an then i deleted "playwright-chromium": "^1.2.1" from json file and uploaded new layer,
with

  "dependencies": {
    "playwright-aws-lambda": "^0.5.2",
    "playwright-core": "npm:[email protected]"
  }

this does not help.

am i doing something wrong?

@aslushnikov
Copy link
Collaborator

Closing as dupe of #2905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants