JupiterOne / playwright-aws-lambda

Support for running Microsoft's Playwright on AWS Lambda and Google Cloud Functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

errorMessage 'Cannot read property 'launch' of undefined

jamesgrubb opened this issue · comments

commented

Hello, I'm running the example code using Netlify functions and receiving the following error -
{ "errorType": "TypeError", "errorMessage": "Cannot read property 'launch' of undefined", "trace": [ "TypeError: Cannot read property 'launch' of undefined", " at Object.launchChromium (/var/task/src/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/src/makescreengrab.js:8:25)" ] }

commented

Hello again. the code im running is
`const playwright = require('playwright-aws-lambda');

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

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

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

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

};`

and the error is
{ "errorType": "TypeError", "errorMessage": "browser.defaultContext is not a function", "trace": [ "TypeError: browser.defaultContext is not a function", " at Runtime.exports.handler (/var/task/src/makescreengrab.js:9:39)" ] }

Are you using 1.0.2 version?

Hey @jamesgrubb. Try using const context = await browser.newContext(); instead. .defaultContext() is no longer supported in playwright-core.

I'm going to go ahead and close this out, but please feel free to re-open or open another issue if you have questions or believe that there is a bug. Thanks!

Hi,

I am getting the same error:

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();
    }
  }
};

I am using:
"playwright-aws-lambda": "^0.5.2",
"playwright-core": "^1.2.1",

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)"
  ]
}

what could be a problem?
tnx a lot

what could be a problem?

use

import * as playwright from 'playwright-aws-lambda';