{"id":15433795,"url":"https://github.com/yusukeiwaki/playwright-python-remote","last_synced_at":"2025-04-19T18:08:10.729Z","repository":{"id":43127052,"uuid":"383833338","full_name":"YusukeIwaki/playwright-python-remote","owner":"YusukeIwaki","description":"Enables us to use playwright-python on pure-Python environment","archived":false,"fork":false,"pushed_at":"2022-03-16T19:03:12.000Z","size":126,"stargazers_count":21,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-18T08:31:36.258Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YusukeIwaki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-07T14:50:26.000Z","updated_at":"2024-09-15T14:50:08.000Z","dependencies_parsed_at":"2022-08-12T10:20:49.198Z","dependency_job_id":null,"html_url":"https://github.com/YusukeIwaki/playwright-python-remote","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YusukeIwaki%2Fplaywright-python-remote","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YusukeIwaki%2Fplaywright-python-remote/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YusukeIwaki%2Fplaywright-python-remote/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YusukeIwaki%2Fplaywright-python-remote/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YusukeIwaki","download_url":"https://codeload.github.com/YusukeIwaki/playwright-python-remote/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240404718,"owners_count":19796063,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T18:35:28.573Z","updated_at":"2025-03-02T17:30:28.745Z","avatar_url":"https://github.com/YusukeIwaki.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# playwright-remote\n\nEnables us to execute [playwright-python](https://github.com/microsoft/playwright-python) scripts on **Pure-Python environment**.\n\n![image](README/structure.png)\n\n## Setup\n\n```\npip install git+https://github.com/YusukeIwaki/playwright-python-remote\n```\n\n## Example\n\nFor communicating with Playwright server:\n\n```py\nfrom playwright_remote.sync_api import sync_playwright_remote\n\nwith sync_playwright_remote('ws://127.0.0.1:8080/ws') as playwright:\n  with playwright.chromium.launch() as browser:\n    page = browser.new_page()\n    page.goto('https://github.com/YusukeIwaki')\n    page.screenshot(path='YusukeIwaki.png')\n```\n\nJust replace `sync_playwright` with `sync_playwright_remote('ws://xxxxxxx/ws')`.\n\n---\n\nFor communicating with Playwright Browser server:\n\n```py\nfrom playwright_remote.sync_api import connect_to_browser\n\nwith connect_to_browser('ws://127.0.0.1:xxxxx/xxxxxxxxxxxxxxxxxxxxxx') as browser:\n  page = browser.new_page()\n  page.goto('https://github.com/YusukeIwaki')\n  page.screenshot(path='YusukeIwaki.png')\n```\n\n\n### Launch Playwright server\n\nWe have to prepare Playwright server using playwright CLI.\n\nIn local development environment (Node.js is required), just execute:\n\n```\nnpx playwright@1.20.0 install \u0026\u0026 npx playwright@1.20.0 run-server\n```\n\nFor deploying to PaaS servers, we can use Playwright official Docker image: https://hub.docker.com/_/microsoft-playwright\n\n```Dockerfile\nFROM mcr.microsoft.com/playwright:v1.20.0\n\nWORKDIR /root\nRUN npm install playwright@1.20.0 \u0026\u0026 ./node_modules/.bin/playwright install\nCMD [\"./node_modules/.bin/playwright\", \"run-server\"]\n```\n\nHeroku example can be found [here](https://github.com/YusukeIwaki/playwright-python-playWithWebSocket/blob/main/heroku.yml).\n\n### Launch Playwright Browser server\n\nWe can also share only one browser environment via WebSocket.\n\n```\nnpx playwright@1.20.0 install \u0026\u0026 npx playwright@1.20.0 launch-server --browser firefox\n```\n\nNote that the functionality of CLI for launch-server is not so rich.\nFor sharing more detailed environment, we have to prepare JavaScript server code like below:\n\n```js\nconst playwright = require('playwright')\n\n// https://playwright.dev/docs/api/class-browsertype/#browser-type-launch-server\noption = {\n  channel: 'chrome-canary',\n  headless: false,\n  port: 8080,\n}\nplaywright.chromium.launchServer(option).then((server) =\u003e { console.log(server.wsEndpoint()) })\n```\n\n### Execute Python script on Alpine Linux environment\n\nSince playwright-remote works on Pure-Python environment, it works also on Alpine Linux.\n\nUnfortunately, `pip install playwright` cannot be executed on Alpine. We have to install playwright from git at this moment.\n\n```Dockerfile\nFROM python:3.9-alpine\n\nRUN apk add --no-cache --virtual .install-deps build-base curl git \\\n    \u0026\u0026 pip install git+https://github.com/microsoft/playwright-python@v1.20.0 \\\n    \u0026\u0026 pip install git+https://github.com/YusukeIwaki/playwright-python-remote \\\n    \u0026\u0026 apk del .install-deps\n```\n\nNow, we can enjoy Playwright on the Docker image :)\nNote that WebSocket endpoint URL should be set properly to `sync_playwright_remote(\"ws://xxxxxxxxx/ws\")`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusukeiwaki%2Fplaywright-python-remote","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyusukeiwaki%2Fplaywright-python-remote","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyusukeiwaki%2Fplaywright-python-remote/lists"}