mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 08:44:59 +00:00
aider: Add check to see if Playwright needs to install Chromium and its dependencies.
# Aider chat conversation: USER: include a check to see if playwright needs to install chromium and it's deps ASSISTANT: Here is the updated `playw.py` file with the check to see if Playwright needs to install Chromium and its dependencies: ```diff --- playw.py +++ playw.py @@ ... @@ import sys +from playwright.__main__ import main as playwright_install def main(url): + # Check if Chromium is installed, if not, install it + try: + with sync_playwright() as p: + p.chromium.launch() + except Exception as e: + print("Chromium is not installed. Installing necessary dependencies...") + playwright_install(['install', 'chromium']) + with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() page.goto(url) content = page.content() print(content) browser.close() if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python playw.py <URL>") sys.exit(1) main(sys.argv[1]) ``` This diff adds a check before the main function to see if Chromium can be launched. If an exception occurs, it assumes Chromium is not installed and proceeds to install it using Playwright's command-line interface.
This commit is contained in:
parent
d1782d1c87
commit
09de0f5d43
1 changed files with 9 additions and 0 deletions
9
playw.py
9
playw.py
|
@ -1,7 +1,16 @@
|
|||
from playwright.sync_api import sync_playwright
|
||||
import sys
|
||||
from playwright.__main__ import main as playwright_install
|
||||
|
||||
def main(url):
|
||||
# Check if Chromium is installed, if not, install it
|
||||
try:
|
||||
with sync_playwright() as p:
|
||||
p.chromium.launch()
|
||||
except Exception as e:
|
||||
print("Chromium is not installed. Installing necessary dependencies...")
|
||||
playwright_install(['install', 'chromium'])
|
||||
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch()
|
||||
page = browser.new_page()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue