Reputation: 1
playwright._impl._errors.TargetClosedError: Browser.new_page: Target page, context or browser has been closed Been launching the chromium browser instance on my aws lambda with no issues until recently faced this kind of issue. The browser fails to initialize and is causing my whole functionality down. I've built the local image and tested it on docker, the app functions fine. This issue is only occuring on aws lambda
My browser launch configurations are :
async with async_playwright() as playwright:
browser_path = find_chromium_path()
executable_path = f"{browser_path}/chrome-linux/chrome"
# Local development
if not os.path.exists(executable_path):
executable_path = None
browser = await playwright.chromium.launch(headless=True,
executable_path=executable_path,
args=[
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--disable-gpu",
"--single-process",
"--no-zygote",
"--disable-audio-output",
"--disable-software-rasterizer",
"--disable-webgl",
"--disable-web-security",
"--disable-features=LazyFrameLoading",
"--disable-features=IsolateOrigins",
"--disable-background-networking"
]
)
Is there any workaround for this problem?
Upvotes: 0
Views: 705
Reputation: 1
What works for me is increasing the memory size of the lambda function to a higher value (128MB to 3008MB).
Upvotes: 0
Reputation: 106
--single-process
and --no-zygote
flags made the stuff working for me on AWS Lambda with playwright v1.46.0
Upvotes: 0
Reputation: 1
Spent 19 hours on this as well... The answer is in the args. The only args you need are:
args=['--no-sandbox', '--disable-setuid-sandbox','--disable-gpu','--single-process']
That should prevent the error! Lmk if it works
Upvotes: 0