playwright-python advanced setup

5.3k views Asked by At

I am trying to do a custom setup for playwright for use with python similar to my selenium setup, however I'm not at all familiar with Node.js and the only useful guide I could find is: https://playwright.dev/#version=v1.4.2&path=docs%2Finstallation.md&q=skip-browser-downloads

So my question is: If I wanted to install only the chrome library with a custom chrome path (I need to use a specific chrome version) how do I do it with pip? The guide for node uses environment vars. Do they work for pip as well?

P.S: pip search playwright doesn't show playwright-chrome in search results as the above link mentions.

1

There are 1 answers

0
arjunattam On BEST ANSWER

Thanks for the question. I'll share what's possible today, and we would be happy to make changes if you could share your scenario as an issue on playwright-python.

playwright-python can work with environment variables like outlined in the linked doc. For example, you can set environment variable for PLAYWRIGHT_BROWSERS_PATH to specify a custom location for your browser binaries.

It is recommended to use Playwright against bundled browser binaries, since Playwright can often depend on browser-side changes that might not be available in older versions. These browser-side changes are done with the intent to improve execution reliability and breadth of Playwright capabilities.

In case you do want to use Playwright against a non-bundled browser binary, you can set the executablePath while launching a browser. For example, the script below launches Edge instead of the bundled Chromium binary.

Python 3.8.0 (default, Sep 21 2020, 12:25:40)
[Clang 12.0.0 (clang-1200.0.32.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from playwright import sync_playwright
>>> pw = sync_playwright().start()
>>> browser = pw.chromium.launch(headless=False, executablePath='/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev')

We do not provide browser specific packages like playwright-chromium for Python today, but we are happy to collect feedback on it and make changes.