chrome-remote-interface icon indicating copy to clipboard operation
chrome-remote-interface copied to clipboard

Support browserless.io:

Open itayadler opened this issue 1 year ago • 0 comments

Context

browserless.io only supports connecting to the browser websocket, and not to a target (page) websocket, so in order to use it, skip straight to PageSession.start_link:

{:ok, page} =
  ChromeRemoteInterface.PageSession.start_link(
    "wss://chrome.browserless.io/?token=your_token"
  )
{:ok, targetResult} =
  ChromeRemoteInterface.RPC.Target.createTarget(page, %{
    url: "https://google.com",
    width: 1280,
    height: 800
  })

targetId = targetResult["result"]["targetId"]

{:ok, sessionResult} =
  ChromeRemoteInterface.RPC.Target.attachToTarget(page, %{targetId: targetId, flatten: true})

sessionId = sessionResult["result"]["sessionId"]
{:ok, screenshot1} =
  ChromeRemoteInterface.RPC.Page.captureScreenshot(page, %{format: "png"},
    session_id: sessionId
  )

Notice that we need to pass the session_id to each command, otherwise without the session_id the command will run on the browser context, in other words it will fail for all commands that are related to the page.

  • Allow to pass session_id for ChromeRemoteInterface.RPC
  • Handle ssl_closed in websocket
  • Update tot json

itayadler avatar Feb 15 '24 08:02 itayadler