Giter Site home page Giter Site logo

jupiterone / playwright-aws-lambda Goto Github PK

View Code? Open in Web Editor NEW
360.0 16.0 49.0 83.4 MB

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

License: MIT License

JavaScript 28.55% TypeScript 66.19% Shell 5.27%
playwright puppeteer lambda aws cloud google function

playwright-aws-lambda's Introduction

playwright-aws-lambda

CI NPM

Support for Playwright running on AWS Lambda and Google Cloud Functions.

NOTE: Currently only Chromium is supported.

Install

npm install playwright-core playwright-aws-lambda --save

Usage

This package works with the nodejs10.x, nodejs12.x, nodejs14.x, nodejs16.x and nodejs18.x AWS Lambda runtimes out of the box.

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

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

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

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

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

API

Method / Property Returns Description
launchChromium {!Promise<playwright.ChromiumBrowser>} Launches the Chromium browser.
loadFont(url) {Promise<void>} Downloads and activates a custom font

Loading additional fonts

If you need custom font support by e.g. emojicons in your browser, you have to load it by using the loadFont(url: string) function before you launch the browser.

await loadFont(
  'https://raw.githack.com/googlei18n/noto-emoji/master/fonts/NotoColorEmoji.ttf'
);

Thanks / Credits

This project is based on the work of chrome-aws-lambda.

playwright-aws-lambda's People

Contributors

austinkelleher avatar dependabot[bot] avatar erichs avatar gulshansainis avatar ijin avatar jablonnc avatar jsulpis avatar mxschmitt avatar ollnixon avatar s12v avatar smithki avatar yury-s avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

playwright-aws-lambda's Issues

Some characters are sticking together after PDF print

Example of the issue:
sticky

Code snippet:

try {
  const browser = await launchChromium({ headless: true })
  const page = await browser.newPage({
    viewport: {
      width: 868,
      height: 500,
    },
  })
  const nextURL = new URL(url)
  await page.goto(nextURL.toString())

  const { getHeaderTemplate, getFooterTemplate, margin } = templates[type]
  const [headerTemplate, footerTemplate] = await Promise.all([
    getHeaderTemplate(templateProps),
    getFooterTemplate(templateProps),
  ])

  const buffer = await page.pdf({
    displayHeaderFooter: true,
    headerTemplate,
    footerTemplate,
    margin,
    printBackground: true,
  })

  const compressed = zlib.gzipSync(buffer)
  const contentEncoding = 'gzip'

  const filename = 'filename.pdf'
  const s3Key = 'mykey/'.concat(filename)
  const contentType = 'application/pdf'
  const putObjectParams = {
    Bucket: s3Bucket,
    Key: `public/${s3Key}`,
    ContentType: contentType,
    ContentEncoding: contentEncoding,
    Body: compressed,
  }

  await Promise.all([s3.putObject(putObjectParams).promise(), browser.close()])

  return {
    statusCode: 200,
    headers: defaultHeaders,
    body: {
      s3Key,
      filename,
      contentType,
      contentEncoding,
    },
  }
} catch (error) {
  console.error(error)
  return {
    statusCode: 500,
    headers: defaultHeaders,
    body: { error: error.message },
  }
}

Further explanation:

  1. A URL is sent to the lambda.
  2. The lambda spins up a headless Chromium browser and navigates to the URL.
  3. The page is captured as a pdf and sent to S3.
  4. The lambda returns the S3 key, which allows the user to download the PDF from S3.

Help & Guidance please.

Update Chromium to latest version

The current contained Chromium version is quite outdated, since Playwright relies on the latest features, it would be good to update it to the latest Beta or Canary.

Add support for 18.x nodejs

We recently upgraded nodejs to 18.x but hit following errors

/tmp/chromium: error while libraries: shared file: No such file libnss3.so: cannot open shared object or directory

Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.Error

Downgrading it to 16.x solved the issues.

--

AWS Lambda supports nodejs 18.x since Nov, 2022

How to increase timeout for playwright

Hi There,

I am runing playwright in AWS lambda using this package, it is great.
The page which I testing is very slow, how can I increase the default timeout, so that I still wait for the page loading.
Timeout 30000ms exceeded.

Emoji's showing Square Boxes

Hello,
I use the package to generate screenshot for various links and webpages. I am getting an issue rendering Emojis, as whenever I take a SS, the emojis are all turned to boxes. Do I need to install any specific plugin or anything

page.goto() throwing error continuously in AWS Lambda with playwright-aws-lambda

Lambda 1:
playwright-aws-lambda v0.9.0
Node 16

Lambda 2:
playwright-aws-lambda v0.10.0
Node 18

AWS Lambda
CI/CD Gitlab

When trying to go to a URL with page.goto(), getting continuous error - 'Error: page.goto: Target page, context or browser has been closed'.
At handler level the error says - "TypeError: Cannot read properties of undefined (reading 'close')\n at d. (/var/task/src/handler.js:1:17387)\n at Generator.next ()\n at a (/var/task/src/handler.js:1:15631)"

The above error in occurring in lambdas which got built by Gitlab pipeline on/after April 18. The same code is still working fine for the lambdas that were build and deployed before April 18.

The deployment packages for old and new deployments are totally same - node module versions and configs.

Any recent updates somewhere would have affected this? TIA.

errorMessage 'Cannot read property 'launch' of undefined

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

Download event not caught and always times out

Thanks a bunch for creating this awesome package.

I was having an issue with the download event. It works great when I try to execute my code locally (serverless invoke local) but when I deploy this via serverless deploy, the waitForEvent('download') times out.

Here's the code:

  const { page, browser } = await openWebpage(URL);

  const [download] = await Promise.all([
    // Start waiting for the download
    page.waitForEvent('download'),
    // Perform the action that initiates download
    page.click(`#${BTN_ID}`),
  ]);

Here's the openWebpage function:

export async function openWebpage(url) {
  const browser = await playwright.launchChromium();
  const context = await browser.newContext({
    acceptDownloads: true,
  });

  const page = await context.newPage();
  await page.goto(url);

  return { page, browser: context };
}

A similar issue was posted in playwright's official repo here.
In that same issue, I've commented about my issue as well, here.

I guess since this package was created based on chrome-aws-lambda, which is for puppeteer basically, and puppeteer does not support download event, so it wasn't included in this package as well. But that's just a random guess. I'd love to help in any way to get this issue fixed.

Hope to hear from you soon.

Target page, context or browser has been closed

I am following the example, creating a browser with await playwright.launchChromium({}) and then creating a context and context.newPage.

I always get this error: "Target page, context or browser has been closed"

Avoid path conflicts with chrome-aws-lambda

Hi! Thank you for all the hard work in this library! ๐Ÿ‘

I discovered that this library is using exactly the same paths for chrome binaries as chrome-aws-lambda ( https://github.com/alixaxel/chrome-aws-lambda/blob/master/source/index.js#L166 ). This makes using both libraries in the same lambda a bit cumbersome. I would like to suggest putting the inflated binaries in a directory, for example /tmp/playwright-aws-lambda/chromium, or adding a prefix to the names.

I would be glad to help with a PR to tackle this issue ๐Ÿ˜ƒ .

A bonus thing that is present in chrome-aws-lambda, and missing in this library is the ability to await on executablePath (currently I have to inflate the files manually if I don't want to launch the browser).

Update chromium.br

Hello, it seems that current version of chromium.br file doesn't support node 16.x version. (eg. String.prototype.replaceAll is not supported in this version)

is there any official support for updating version of chromium?

Set up npm auto-publish

We should add a GitHub action for auto-publishing to npm when a new version + git tag is added and the branch is master.

Cannot read property 'launch' of undefined

Tried integrating playwright-aws-lambda with an existing project and got an error, so went back to basics, started a new npm project and followed the steps in the README as follows:

  • npm install playwright-core playwright-aws-lambda --save
  • copied the example under the Usage section and pasted it into my index file.
  • uploaded my function to lambda with nodejs12.x runtime.

When running the lambda I get the following error:

ERROR	Invoke Error 	{"errorType":"TypeError","errorMessage":"Cannot read property 'launch' of undefined","stack":
["TypeError: Cannot read property 'launch' of undefined","    at Object.launchChromium (/var/task/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)"]}

Apologies if this is user error. I did some research before logging this to see if there was an obvious fix, and simplified the repro process by using the bare minimum example code instead of my own code.

Recording video on lambda

Has anyone successfully got video recording to work on lambda + playwright?

Working fine locally, but after deploying to lambda:

browserContext.newPage: Executable doesn't exist at /home/sbx_user1051/.cache/ms-playwright/ffmpeg-1007/ffmpeg-linux

Attempting to install ffmpeg via a lambda layer results in a package size that's too big for lambda.

Attempting to install ffmpeg and set the path via:

const pathToFfmpeg = require('ffmpeg-static');
const ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(pathToFfmpeg);

Results in the same error as above.

request.body return null although there is a body

hi,

I'm using page.on('request'.. to check request parameters. Locally everything runs with on issue, logging the Login/Login post body with no issues. But when deployed on AWS Lambda the body is null. Using the code bellow.

versions:
"playwright-aws-lambda": "^0.6.0",
"playwright-core": "^1.7.1"

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

module.exports.plTest = async event => {
    let browser = null;
    try {
        const browser = await playwright.launchChromium();
        const context = await browser.newContext();
        const page = await context.newPage();
        page.on('request', request=> {
            let url = request.url();
            let requestHeaders = request.headers();
            let body = request.postData();
            let body2 = request.postDataJSON();
            let method = request.method();
            console.log("URL: ",url);
            console.log(`${method} body: `,body);
            console.log(`${method} body2: `,body2);
            console.log("\n\n");
        });
        await page.goto('https://dashboard.sleeknote.com/login');
        const startUrl = await page.url();
        console.log("Fill in user email");
        await page.fill("#email", "[email protected]");
        console.log("Fill in user password");
        await page.fill("#password", "ZZZ1ZZ2ZZ3");
        page.waitForTimeout(3000);
        console.log("Click submit button");
        await page.click('[type="submit"]');
        page.waitForSelector(".dashboard");
        console.log("Assert user is inside dashboard");
        const currentUrl = await page.url();
        console.log("currentUrl: ", currentUrl);
        console.log('Page title: ', await page.title());
    } catch (error) {
        throw error;
    } finally {
        if (browser) {
            await browser.close();
        }
    }
    return {
        statusCode: 200,
        body: JSON.stringify(
            {
                message: 'Go Serverless v1.0! Your function executed successfully!',
                input: event,
            },
            null,
            2
        ),
  };
};

Blank PDF pages

I am getting blank PDF pages when deployed to LAMBDA but it works fine locally.

What's interesting is that the PDF pages although they are blank, they have the correct amount of pages.

I am not doing anything fancy:

`
this.browser = await playwright.launchChromium({
headless: true
});

this.ctx = await this.browser.newContext();
const page = await this.ctx.newPage();
await page.goto(url);
pdf = await page.pdf();
`

It's running on expressjs, deployed with serverless. I get no error, I get a valid PDF buffer back. I am able to open the PDF file, but the pages are always blank.

Google Cloud Functions?

Docs allude to this. Does support for Google Cloud Functions exist as part of this package? Perhaps it supports currently, but the package naming is confusing.

`npm audit` reports vulnerabilities

There are transitive dependencies of lambdafs which depend on vulnerable versions of minimist and bl. It's not clear to me how this vulnerability might affect playwright-aws-lambda in practice, but it does create scary-looking noise upon npm install.

An example of npm install playwright-aws-lambda output on a fresh project:

up to date, audited 20 packages in 451ms

3 vulnerabilities (2 moderate, 1 critical)

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

And the npm audit report:

# npm audit report

bl  3.0.0
Severity: moderate
Remote Memory Exposure in bl - https://github.com/advisories/GHSA-pp7h-53gx-mx7r
fix available via `npm audit fix`
node_modules/lambdafs/node_modules/bl

minimist  <=1.2.5
Severity: critical
Prototype Pollution in minimist - https://github.com/advisories/GHSA-xvch-5gv4-984h
Prototype Pollution in minimist - https://github.com/advisories/GHSA-vh95-rmgr-6w4m
fix available via `npm audit fix`
node_modules/lambdafs/node_modules/minimist
  mkdirp  0.4.1 - 0.5.1
  Depends on vulnerable versions of minimist
  node_modules/lambdafs/node_modules/mkdirp

3 vulnerabilities (2 moderate, 1 critical)

To address all issues, run:
  npm audit fix

Unfortunately, npm audit fix does nothing to resolve the issue. This appears to be a known issue in NPM itself.

There's seemingly a bazillion different places where this specific issue could be resolved upstream, but getting support for packages that appear to be stale is a challenge. Perhaps a solution can be implemented directly by playwright-aws-lambda?

Cannot find module 'playwright-core'

Thank you for this library, I have found playwright to be superior to puppeteer and would prefer to use it on AWS.

Unfortunately currently I am getting an error whenever I try to use it, including the simple demo code in the README.

internal/modules/cjs/loader.js:638                                                        
    throw err;                                                                            
    ^                                                                                     
                                                                                          
Error: Cannot find module 'playwright-core'                                               
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)           
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)                      
    at Module.require (internal/modules/cjs/loader.js:692:17)                             
    at require (internal/modules/cjs/helpers.js:25:18)                                    
    at Object.<anonymous> (E:\Nodejs\AllTheComps\playwright\dev\node_modules\playwright-aws-lambda\dist\src\chromium.js:5:20)                                                       
    at Module._compile (internal/modules/cjs/loader.js:778:30)                            
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)              
    at Module.load (internal/modules/cjs/loader.js:653:32)                                
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)                              
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)                       

The offending line is:
const playwright = require("playwright-core");

I'm developing on Windows but this happened on Lambda as well. I have npm install'd playwright-core, it definitely exists in node_modules

How can I read which port the browser has opened on?

I have tried specifying a port using "--remote-debugging-port=9222" as an option which works locally. However when deployed to vercel the option causes an error.

However all I need is to know the actual port chromium has opened on as I want to run lighthouse.

Any idea how I can get at it?

Thank you

Help with lambda layer

Can you provide an example to how deploy this package as lambda layer? For example, in chrome-aws-lambda use this command to build a .zip file to upload to AWS Lambda Layer

git clone --depth=1 https://github.com/alixaxel/chrome-aws-lambda.git && \
cd chrome-aws-lambda && \
make chrome_aws_lambda.zip

EDIT:
I found a solution: add Makefile to this project for use the same command as chrome-aws-lambda. Also, I made a pull request with this change. Tell me if you need more info.

During the execution of a lambda, if there is concurrent processing, an error will be reported

const [b1,b2] = await Promise.all([playwright.launchChromium({
headless: true,
}), playwright.launchChromium({
headless: true,
})])

browserType.launch: spawn ETXTBSY\nCall log:\n  - <launching> /tmp/chromium --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,HttpsUpgrades --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --autoplay-policy=user-gesture-required --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-dev-shm-usage --disable-domain-reliability --disable-extensions --disable-features=AudioServiceOutOfProcess --disable-hang-monitor --disable-ipc-flooding-protection --disable-notifications --disable-offer-store-unmasked-wallet-cards --disable-popup-blocking --disable-print-preview --disable-prompt-on-repost --disable-renderer-backgrounding --disable-setuid-sandbox --disable-speech-api --disable-sync --disk-cache-size=33554432 --hide-scrollbars --ignore-gpu-blacklist --metrics-recording-only --mute-audio --no-default-browser-check --no-first-run --no-pings --no-sandbox --no-zygote --password-store=basic --use-gl=swiftshader --use-mock-keychain --single-process --user-data-dir=/tmp/playwright_chromiumdev_profile-i3Vycb --remote-debugging-pipe --no-startup-window\n",
"trace": [
    "browserType.launch: spawn ETXTBSY",
    "Call log:",
    "  - <launching> /tmp/chromium --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,HttpsUpgrades --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --autoplay-policy=user-gesture-required --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-dev-shm-usage --disable-domain-reliability --disable-extensions --disable-features=AudioServiceOutOfProcess --disable-hang-monitor --disable-ipc-flooding-protection --disable-notifications --disable-offer-store-unmasked-wallet-cards --disable-popup-blocking --disable-print-preview --disable-prompt-on-repost --disable-renderer-backgrounding --disable-setuid-sandbox --disable-speech-api --disable-sync --disk-cache-size=33554432 --hide-scrollbars --ignore-gpu-blacklist --metrics-recording-only --mute-audio --no-default-browser-check --no-first-run --no-pings --no-sandbox --no-zygote --password-store=basic --use-gl=swiftshader --use-mock-keychain --single-process --user-data-dir=/tmp/playwright_chromiumdev_profile-i3Vycb --remote-debugging-pipe --no-startup-window",
    "",
    "    at Object.launchChromium (/opt/nodejs/node_modules/playwright-aws-lambda/dist/src/chromium.js:97:47)",
    "    at async Downloader.getBrowserContext (/var/task/src/app.js:204:19)",
    "    at async Downloader.downloadPage (/var/task/src/app.js:47:25)",
    "    at async Downloader.downloadPageByBatch (/var/task/src/app.js:6:15)",
    "    at async Runtime.handler (/var/task/src/app.js:318:13)"
]

}

Struggling on aws lambda.

I have a small express API that runs a scraper on Instagram that gets the ImgURL and descriptionText, I have moved this over to aws lambda as I was originally trying to run this on a Vercel serverless function. The function can run but takes longer than 10 seconds, which times out on the free version. Any help is appreciated., I keep timing out.

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

exports.handler = async (event) => {
  const link = event.link;
  if (!link.includes('instagram')) {
    throw new Error('Not an Instagram link');
  }

  try {
    const browser = await playwright.launchChromium({headless: true});
    const context = await browser.newContext();

    const page = await context.newPage();
    await page.goto(link);

    const imgClass = 'img.x5yr21d.xu96u03.x10l6tqk.x13vifvy.x87ps6o.xh8yej3';
    const descClass = 'h1._aacl._aaco._aacu._aacx._aad7._aade';

    const image = await page.waitForSelector(imgClass);
    const imageUrl = await image.getAttribute('src')

    const desc = await page.waitForSelector(descClass);
    const descText = await desc.innerText()

    await browser.close();

    return {
      statusCode: 200,
      body: JSON.stringify({imageUrl, descText}),
    };
  } catch (error) {
    console.error(error);

    return {
      statusCode: 400,
      body: JSON.stringify({error: error.message}),
    };
  }
};

=

Packages are at:

  "dependencies": {
    "playwright-aws-lambda": "^0.10.0",
    "playwright-core": "^1.32.0"
  }

Aws lambda
Node v16.x
Memory 1600
x86_64

can't launch playwright-aws-lambda with a user profile

Using versions;
"playwright-aws-lambda": "^0.6.0",
"playwright-core": "^1.7.1",

Trying to run pl-aws-chrome with a specific user profile fails, 'launchPersistentContext' is not defined for pl-aws-chrome, and passing as args fail as well. Not sure how to solve this issue, could use some help

running

const playwrightAWS = require('playwright-aws-lambda');
chromium = await playwrightAWS.launchChromium({headless: true, userDataDir: './user_profiles/'});

will result with:

Uncaught:
Error: browserType.launch: userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead
    at Object.assert (SOME_PATH/node_modules/playwright-core/lib/utils/utils.js:80:15)
    at SOME_PATH/node_modules/playwright-core/lib/client/browserType.js:56:21
    at BrowserType._wrapApiCall (SOME_PATH/node_modules/playwright-core/lib/client/channelOwner.js:77:34)
    at BrowserType.launch (SOME_PATH/node_modules/playwright-core/lib/client/browserType.js:55:21)
    at Object.launchChromium (SOME_PATH/node_modules/playwright-aws-lambda/dist/src/chromium.js:97:47)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async repl:1:35

passing directory with profile flags in args:

chromium = await playwrightAWS.launchChromium({headless: true, args: ['--profile-directory=./user_profiles/', '--user-data-dir=./user_profiles/']});

Uncaught:
browserType.launch: Pass userDataDir parameter instead of specifying --user-data-dir argumentError


Integration of anything similar like puppeteer-extra-plugin-stealth

Hello,
Our use case basically needs a OAuth Login like Chrome or facebook for a complete E2E testing.
We are using playwright and running it on lambda. The Normal Login works fine but the OAuth fails due to the headless mode. I found out the package puppeteer-extra-plugin-stealth which is used to bypass bot protection for OAuth.

Is there any way we can use the same plugin in playwright as its a fork from puppeteer?

Error: ENOENT: no such file or directory, open '/var/task/node_modules/playwright-core/browsers.json'

After upgrade Playwright to 1.9.2 this error is happening on Vercel functions.

2021-03-16T19:57:07.806Z	undefined	ERROR	Error: ENOENT: no such file or directory, open '/var/task/node_modules/playwright-core/browsers.json'
    at Object.openSync (fs.js:462:3)
    at Object.readFileSync (fs.js:364:35)
    at new Registry (/var/task/node_modules/playwright-core/lib/utils/registry.js:213:54)
    at new Playwright (/var/task/node_modules/playwright-core/lib/server/playwright.js:46:23)
    at Object.createPlaywright (/var/task/node_modules/playwright-core/lib/server/playwright.js:59:12)
    at setupInProcess (/var/task/node_modules/playwright-core/lib/inprocess.js:24:37)
    at Object.<anonymous> (/var/task/node_modules/playwright-core/lib/inprocess.js:42:18)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/var/task/node_modules/playwright-core/browsers.json'
}
RequestId: fafc5e6c-b338-4ba2-90b0-a019fd78923b Error: Runtime exited with error: exit status 1
Runtime.ExitError

Error while loading shared libraries: libnss3

I got

[pid=24][err] /tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

with runtime: Node.js 16.x and this - sample code:

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

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

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

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

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

Keep browser open between Lambda invocations

Whenever I try to keep the browser open between invocations, it seems like the browser gets closed/killed.

This is the error I'm getting after the first invocation:

{
    "name": "Error",
    "stack": [
        ": Protocol error (Target.createTarget): Browser closed.",
        "==================== Browser output: ====================",
        "[pid=25][err] #2 0x5652544896c5 (/tmp/chromium+0x48e46c4)",
        "[pid=25][err] #3 0x7fa34c9137e0 (/usr/lib64/libpthread-2.26.so+0x117df)",
        "[pid=25][err] #4 0x7fa34bbf0c20 __GI_raise",
        "[pid=25][err] #5 0x7fa34bbf20c8 __GI_abort",
        "[pid=25][err] #6 0x565254488625 (/tmp/chromium+0x48e3624)",
        "[pid=25][err] #7 0x56525440a1c2 (/tmp/chromium+0x48651c1)",
        "[pid=25][err] #8 0x5652534b3c78 (/tmp/chromium+0x390ec77)",
        "[pid=25][err] #9 0x56525358908d (/tmp/chromium+0x39e408c)",
        "[pid=25][err] #10 0x56525331b28b (/tmp/chromium+0x377628a)",
        "[pid=25][err] #11 0x56525331b1b6 (/tmp/chromium+0x37761b5)",
        "[pid=25][err] #12 0x5652535cdd21 (/tmp/chromium+0x3a28d20)",
        "[pid=25][err] #13 0x5652535c2ec4 (/tmp/chromium+0x3a1dec3)",
        "[pid=25][err] #14 0x5652535c2bc4 (/tmp/chromium+0x3a1dbc3)",
        "[pid=25][err] #15 0x565255b3dba9 (/tmp/chromium+0x5f98ba8)",
        "[pid=25][err] #16 0x565254583287 (/tmp/chromium+0x49de286)",
        "[pid=25][err] #17 0x565255b49c8a (/tmp/chromium+0x5fa4c89)",
        "[pid=25][err] #18 0x565255b49e09 (/tmp/chromium+0x5fa4e08)",
        "[pid=25][err] #19 0x5652529f9b2d (/tmp/chromium+0x2e54b2c)",
        "[pid=25][err] #20 0x5652529f5db8 (/tmp/chromium+0x2e50db7)",
        "[pid=25][err] #21 0x565253e289b3 (/tmp/chromium+0x42839b2)",
        "[pid=25][err] #22 0x565255b482f8 (/tmp/chromium+0x5fa32f7)",
        "[pid=25][err] #23 0x565255b47598 (/tmp/chromium+0x5fa2597)",
        "[pid=25][err] #24 0x5652532236ae (/tmp/chromium+0x367e6ad)",
        "[pid=25][err] #25 0x5652532232b6 (/tmp/chromium+0x367e2b5)",
        "[pid=25][err] #26 0x56525321f780 (/tmp/chromium+0x367a77f)",
        "[pid=25][err] #27 0x565254438eeb (/tmp/chromium+0x4893eea)",
        "[pid=25][err] #28 0x56525444982e (/tmp/chromium+0x48a482d)",
        "[pid=25][err] #29 0x5652544495c0 (/tmp/chromium+0x48a45bf)",
        "[pid=25][err] #30 0x5652544a4629 (/tmp/chromium+0x48ff628)",
        "[pid=25][err] #31 0x565254449db5 (/tmp/chromium+0x48a4db4)",
        "[pid=25][err] #32 0x565254426dae (/tmp/chromium+0x4881dad)",
        "[pid=25][err] #33 0x5652531a3dd4 (/tmp/chromium+0x35fedd3)",
        "[pid=25][err] #34 0x5652531a57d2 (/tmp/chromium+0x36007d1)",
        "[pid=25][err] #35 0x565255b45fc6 (/tmp/chromium+0x5fa0fc5)",
        "[pid=25][err] #36 0x56525439c794 (/tmp/chromium+0x47f7793)",
        "[pid=25][err] #37 0x56525439c417 (/tmp/chromium+0x47f7416)",
        "[pid=25][err] #38 0x565255996641 (/tmp/chromium+0x5df1640)",
        "[pid=25][err] #39 0x565254395801 (/tmp/chromium+0x47f0800)",
        "[pid=25][err] #40 0x5652543f549d (/tmp/chromium+0x485049c)",
        "[pid=25][err] #41 0x5652543f51bc (/tmp/chromium+0x48501bb)",
        "[pid=25][err] #42 0x7fa34bbde0ba __libc_start_main",
        "[pid=25][err] #43 0x56525257fa2a _start",
        "[pid=25][err]   r8: 0000000000000000  r9: 00007ffe792bfa70 r10: 0000000000000008 r11: 0000000000000246",
        "[pid=25][err]  r12: 00007ffe792c0e50 r13: 00007ffe792bfd10 r14: 00007ffe792c0e58 r15: aaaaaaaaaaaaaaaa",
        "[pid=25][err]   di: 0000000000000002  si: 00007ffe792bfa70  bp: 00007ffe792bfcc0  bx: 0000000000000006",
        "[pid=25][err]   dx: 0000000000000000  ax: 0000000000000000  cx: 00007fa34bbf0c20  sp: 00007ffe792bfa70",
        "[pid=25][err]   ip: 00007fa34bbf0c20 efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000",
        "[pid=25][err]  trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000",
        "[pid=25][err] [end of stack trace]",
        "[pid=25][err] Calling _exit(1). Core file will not be generated.",
        "    at captureStackTrace (/var/task/node_modules/playwright-core/lib/utils/stackTrace.js:60:17)",
        "    at BrowserContext._wrapApiCall (/var/task/node_modules/playwright-core/lib/client/channelOwner.js:101:58)",
        "    at BrowserContext.newPage (/var/task/node_modules/playwright-core/lib/client/browserContext.js:237:17)",
        "    at Runtime.exports.handler (/var/task/index.js:31:30)"
    ]
}

This is roughly the code I'm using:

const browser = require('playwright-aws-lambda').launchChromium()

exports.handler = async (event, options) => {
  options.callbackWaitsForEmptyEventLoop = false

  const context = await (await browser).newContext()

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

  console.log('Page title: ', await page.title())
}

Do you know if this is a limitation of Lambda, or is there something else going on here? ๐Ÿค”

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.