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

[BUG] Chromium works in dev but fails at build (Executable doesn't exist) #18955

Closed
MuhammadM1998 opened this issue Nov 21, 2022 · 14 comments
Closed

Comments

@MuhammadM1998
Copy link

Context:

  • Playwright Version: 1.28.0 & 1.14.0
  • Operating System: Windows 10 10.0.22621
  • Node.js version: 18.12.1 (LTS)
  • Browser: Chromium
  • Nuxt Version: 3.0 (stable)
  • Nitro Version: 0.6.0 (latest)

Reproduction
Repo , Stackblitz

Code Snippet

import { chromium } from 'playwright-core';
import bundledChromium from 'chrome-aws-lambda';
import { db } from '../db';

export default defineNitroPlugin(async () => {
  const browser = await Promise.resolve(bundledChromium.executablePath).then(
    (executablePath) =>
      !executablePath
        ? chromium.launch({ headless: false }) // Local execution
        : chromium.launch({ executablePath }) // Remote execution
  );

  const context = await browser.newContext();
  const page = await context.newPage();
  await page.goto('https://www.google.com/');
  await page.waitForTimeout(2000);
  await browser.close();

  db.push('works'); // I'm fetching db and showing it at index.html to test if this works
});

Describe the bug
I'm using Playwright in a Nuxt 3 project as a nitro plugin to scrape data from a website then use it in the frontend.

It works in my local maching but not in production or stackblitz (see reproduction link).

I've tried to implement this #2321 comment and it didn't work too.

Vercel Deployment logs
This is what's logged when deploying the repo mentioned above

[info] Building server...
[success] Server built in 549ms
[success] [nitro] Generated public .vercel/output/static
[info] [nitro] Initializing prerenderer
[info] [nitro] Prerendering 3 initial routes with crawler
[error] [unhandledRejection] browserType.launch: Executable doesn't exist 
at /vercel/.cache/ms-playwright/chromium-1033/chrome-linux/chrome
╔═════════════════════════════════════════════════════════════════════════╗
║ Looks like Playwright Test or Playwright was just installed or updated. ║
║ Please run the following command to download new browsers:              ║
║                                                                         ║
║     npx playwright install                                              ║
║                                                                         ║
║ <3 Playwright Team                                                      ║
╚═════════════════════════════════════════════════════════════════════════╝

╔═════════════════════════════════════════════════════════════════════════╗
║ Looks like Playwright Test or Playwright was just installed or updated. ║
║ Please run the following command to download new browsers:              ║
║                                                                         ║
║     npx playwright install                                              ║
║                                                                         ║
║ <3 Playwright Team                                                      ║
╚═════════════════════════════════════════════════════════════════════════╝
at .nuxt/prerender/chunks/nitro/nitro-prerenderer.mjs:340:52
at async .nuxt/prerender/chunks/nitro/nitro-prerenderer.mjs:339:19
[error] [nitro] [dev] [unhandledRejection] Error: browserType.launch: Executable doesn't exist 
at /vercel/.cache/ms-playwright/chromium-1033/chrome-linux/chrome
╔═════════════════════════════════════════════════════════════════════════╗
║ Looks like Playwright Test or Playwright was just installed or updated. ║
║ Please run the following command to download new browsers:              ║
║                                                                         ║
║     npx playwright install                                              ║
║                                                                         ║
║ <3 Playwright Team                                                      ║
╚═════════════════════════════════════════════════════════════════════════╝
@dgozman
Copy link
Contributor

dgozman commented Nov 21, 2022

@MuhammadM1998 I see you are using chromium from 'chrome-aws-lambda' package. Unfortunately, this is not an official Playwright package, and so we are not able to help with such issues.

@dgozman dgozman closed this as completed Nov 21, 2022
@MuhammadM1998
Copy link
Author

@dgozman Would you mind suggesting an alternative to fix the base error then? I used 'chrome-aws-lambda' because I couldn't find an official solution that works. I think you shouldn't close an issue this fast too imo

@dgozman
Copy link
Contributor

dgozman commented Nov 22, 2022

Would you mind suggesting an alternative to fix the base error then?

Sure! But I didn't understand the base issue, unfortunately. Could you explain please?

@dgozman dgozman reopened this Nov 22, 2022
@MuhammadM1998
Copy link
Author

@dgozman using the official package playwright or playwright-core, the scripts runs fine on dev but fails on production with this error browserType.launch: Executable doesn't exist at /root/.cache/ms-playwright/chromium-1015/chrome-linux/chrome
Hence I'm using the chrome-aws-lambda as someone found it solves the problem.

This is a similar question on SO and he used the same package to solve the problem.

These are all similar issues in the playwright repo like #1568, #634, #626

#2404 suggests using the chrome-aws-lambda package to solve it

@dgozman
Copy link
Contributor

dgozman commented Nov 23, 2022

@MuhammadM1998 Playwright is focused on testing scenarios, so running it outside of local/CI environments is out of the project scope, sorry!

However, npx playwright install chromium should work on most systems. If you cannot run it in advance, try running it programmatically before using playwright, as suggested in the SO question linked above. I hope this helps.

@MuhammadM1998
Copy link
Author

npx playwright install chromium should work on most systems. If you cannot run it in advance, try running it programmatically before using playwright, as suggested in the SO question linked above. I hope this helps.

I tried this too but didn't work. Thanks for helping out anyway If I found a solution I'll post it here

@dgozman
Copy link
Contributor

dgozman commented Nov 28, 2022

Closing as per above.

@dgozman dgozman closed this as completed Nov 28, 2022
@ikamanu
Copy link

ikamanu commented Oct 2, 2023

Any luck here, @MuhammadM1998?

@MuhammadM1998
Copy link
Author

@ikamanu Didn't touch it in a while but last thing I remember is now it works in build and hangs in dev 😂

@raphael-caylent
Copy link

I faced the same issue recently, with the small difference that it was on AWS Lambda, running a Python environment. The solution was the following:
1- In my Dockerfile, change the path where browsers are installed:

ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

RUN playwright install --with-deps chromium

On the code, add two flags:
browser = await p.chromium.launch(headless=True, args=["--disable-gpu", "--single-process"])

After these changes, I was able to use Playwright on AWS Lambda successfully.

@IzliaB
Copy link

IzliaB commented Mar 23, 2024

I faced the same issue recently, with the small difference that it was on AWS Lambda, running a Python environment. The solution was the following: 1- In my Dockerfile, change the path where browsers are installed:

ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

RUN playwright install --with-deps chromium

On the code, add two flags: browser = await p.chromium.launch(headless=True, args=["--disable-gpu", "--single-process"])

After these changes, I was able to use Playwright on AWS Lambda successfully.

Hello! I'm encountering the same issue. Do you think you could review my Dockerfile? The difference is that I'm using AdonisJS, which is based on Node.js, so the distinction isn't significant. I asked a question. url issue

@raphael-caylent
Copy link

I faced the same issue recently, with the small difference that it was on AWS Lambda, running a Python environment. The solution was the following: 1- In my Dockerfile, change the path where browsers are installed:

ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

RUN playwright install --with-deps chromium

On the code, add two flags: browser = await p.chromium.launch(headless=True, args=["--disable-gpu", "--single-process"])
After these changes, I was able to use Playwright on AWS Lambda successfully.

Hello! I'm encountering the same issue. Do you think you could review my Dockerfile? The difference is that I'm using AdonisJS, which is based on Node.js, so the distinction isn't significant. I asked a question. url issue

Have you tried the suggestion I mentioned? I think it might work in your case since your error is also about not finding the executable.

@Yeqishen
Copy link

Yeqishen commented Jan 9, 2025

1- In my Dockerfile, change the path where browsers are installed:1-在我的 Dockerfile 中,更改浏览器的安装路径:

I faced the same issue recently, with the small difference that it was on AWS Lambda, running a Python environment. The solution was the following:我最近遇到了同样的问题,差别很小,它是在 AWS Lambda 上运行 Python 环境。解决方案如下: 1- In my Dockerfile, change the path where browsers are installed:1-在我的 Dockerfile 中,更改浏览器的安装路径:

ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

RUN playwright install --with-deps chromium
On the code, add two flags:在代码中添加两个标志: browser = await p.chromium.launch(headless=True, args=["--disable-gpu", "--single-process"])

After these changes, I was able to use Playwright on AWS Lambda successfully.经过这些更改后,我能够在 AWS Lambda 上成功使用 Playwright。

Thank you very much for your advice. My usage scenario is the same as yours. I tried adding the command you wrote to the Dockerfile, but it seems that another error occurred. I wonder if you have the same experience.

BrowserType.launch_persistent_context: Executable doesn't exist at /home/sbx_user1051/.cache/ms-playwright/chromium-1148/chrome-linux/chrome...

This Docker image can run normally in my local test, but this error will occur after deploying to AWS. I don't know why this is happening. The following is my Dockerfile.

`ARG FUNCTION_DIR="/function"

FROM python:3.11-slim AS build-image

ARG FUNCTION_DIR

RUN mkdir -p ${FUNCTION_DIR}
COPY . ${FUNCTION_DIR}

RUN pip install
--target ${FUNCTION_DIR}
awslambdaric

FROM python:3.11-slim

ARG FUNCTION_DIR

WORKDIR ${FUNCTION_DIR}

COPY requirements.txt ./

RUN pip install -r requirements.txt --target ${FUNCTION_DIR}

ENV PLAYWRIGHT_BROWSERS_PATH=/tmp/ms-playwright

RUN pip install playwright==1.49.0
RUN playwright install --with-deps chromium

COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}

ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]

CMD [ "lambda_function.handler" ]`

@raphael-caylent
Copy link

@Yeqishen Based on the error you are getting it seems Playwright is still trying to install the browser in the default location and not on the path /tmp/ms-playwright you configured. I suggest you run this image locally and try to troubleshoot that. Check if the ENV is properly set and if Playwright has permission to access the /tmp/ms-playwright folder.

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

6 participants