microsoft / playwright-python

Python version of the Playwright testing and automation library.
https://playwright.dev/python/
Apache License 2.0
11.55k stars 881 forks source link

[Bug]: If resources are too small, browser objects will crash #2463

Closed tynam-yang closed 2 months ago

tynam-yang commented 3 months ago

Version

1.42

Steps to reproduce

I run a playwright in k8s, and headless=True: 1、Resources: CPU set to 1, memory set to 1 2、When opening a new page or executing context.new_page()

Expected behavior

Program running

Or a recommended minimum resource is specified

Actual behavior

Exception thrown: playwright._impl._errors.Error: Target crashed

Additional context

When I set resource CPU to 2 and memory to 2, the program works fine

Environment

- platform: Linux
- Python Version: 3.10.14
- pytest Version: 8.0.2
- Browser: Chrome
mxschmitt commented 3 months ago

Would it be possible to share a script with us / minimal reproducible which we can run locally?

Thank you!

tython commented 3 months ago

I encountered similar errors

tython commented 3 months ago

1.The dockerfile is as follows

`FROM mcr.microsoft.com/playwright/python:v1.44.0-jammy

LABEL maintainer="yiweitang@yunify.com" version="0.1"

WORKDIR /app

RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone && \ pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

RUN pip install --upgrade pip && \ pip install poetry

COPY pyproject.toml poetry.lock ./

RUN poetry config virtualenvs.create false && \ poetry install --no-dev --no-interaction --no-ansi

ENV PATH="/app/.venv/bin:$PATH"

RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak

RUN sed -i 's@archive.ubuntu.com/@mirrors.aliyun.com/@g' /etc/apt/sources.list && \ sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list && \ sed -i 's@security.ubuntu.com/@mirrors.aliyun.com/@g' /etc/apt/sources.list

RUN apt-get update && \ apt-get install -y \ libglib2.0-0 \ libnss3 \ libnspr4 \ libdbus-1-3 \ libatk1.0-0 \ libatk-bridge2.0-0 \ libcups2 \ libdrm2 \ libatspi2.0-0 \ libx11-6 \ libxcomposite1 \ libxdamage1 \ libxext6 \ libxfixes3 \ libxrandr2 \ libgbm1 \ libxcb1 \ libxkbcommon0 \ libpango-1.0-0 \ libcairo2 \ libasound2 \ vim \ wget \ curl \ iproute2 \ iputils-ping \ ttf-wqy-microhei && \ rm -rf /var/lib/apt/lists/*

COPY . .

CMD ["python", "./main.py"]`

2.Run container docker run -it --rm -v /etc/hosts:/etc/hosts --ipc=host qingcloud/qingcloud-playwright:v0.4 /bin/bash

3.Execute tests within docker python main.py

image

image

tynam-yang commented 3 months ago

Resources: CPU set to 1, memory set to 1. I didn't repeat it.

I started by using page_fixture to open a browser.

If i open a browser using student_page_fixture during the execution, Target crashed occurs

image

Adjust resources when solving a solution: image

mxschmitt commented 3 months ago

Would it be possible to share some something which we can execute locally? Ideally a docker run command which fails? 1 GB should be enough for basic sites.

mxschmitt commented 2 months ago

Closing since its stale. This doesn't like a Playwright bug in particular. We recommend giving the containers more cpu/memory which should help for that scenario. Setting the DEBUG=pw:browser env might yield more debug output, why Chromium isn't able to launch / crashing.