Skip to content

Commit

Permalink
fix: browserless API endpoint for playwright
Browse files Browse the repository at this point in the history
- the recent browserless update apparently changed the API endpoint from "ws://localhost:3000" to "ws://localhost:3000/chrome/playwright", which can be accessed via playwright's "Browsertype.connect()"-method
  - the "connect_over_cdp()"-method seems no longer necessary

for future reference:
- the docs at https://docs.browserless.io/#connect-using-puppeteer-or-playwright appear to be outdated and don't reflect these recent changes
  - use "http://localhost:3000/docs" to look up the most-current documentation for the browserless playwright integration instead
  • Loading branch information
Criamos committed Jan 7, 2025
1 parent 4cdc6a1 commit 7ded74f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions converter/web_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ async def fetchDataPlaywright(cls, url: str):
# relevant docs for this implementation: https://hub.docker.com/r/browserless/chrome#playwright and
# https://playwright.dev/python/docs/api/class-browsertype#browser-type-connect-over-cdp
async with async_playwright() as p:
ws_cdp_endpoint = env.get("PLAYWRIGHT_WS_ENDPOINT")
ws_cdp_endpoint = f"{env.get("PLAYWRIGHT_WS_ENDPOINT")}/chrome/playwright"
if cls._playwright_adblocker:
# advertisements pollute the HTML body and obstruct website screenshots, which is why we try to block
# them from rendering via the built-in adblocker (uBlock Origin) of the browserless docker image.
# see: https://docs.browserless.io/chrome-flags/#blocking-ads
ws_cdp_endpoint = f"{ws_cdp_endpoint}/?blockAds=true"
browser = await p.chromium.connect_over_cdp(endpoint_url=ws_cdp_endpoint)
ws_cdp_endpoint = f"{ws_cdp_endpoint}?blockAds=true"
browser = await p.chromium.connect(ws_endpoint=ws_cdp_endpoint)
browser_context = await browser.new_context()
if cls._playwright_cookies:
# Some websites may require setting specific cookies to render properly
Expand Down

0 comments on commit 7ded74f

Please sign in to comment.