astral icon indicating copy to clipboard operation
astral copied to clipboard

request: provide an example of connecting to an existing browser

Open hunterloftis opened this issue 9 months ago • 1 comments

The documentation only shows how to connect to a cloud-hosted browser service: https://astral.deno.dev/advanced/connect/

Using Astral, how would you connect to a locally-running browser?

hunterloftis avatar Apr 29 '24 15:04 hunterloftis

Seems like a reasonable thing to document. Essentially the process is as simple as running a chromium-like binary with the following flags:

--remote-debugging-port=<SOME_PORT>
--headless=new
--no-first-run
--password-store=basic
--use-mock-keychain
--hide-scrollbars

Technically, only the first one is necessary, though I've found that these flags generally get the best result. One this is running, it'd be as simple as

// Connect to remote endpoint
const browser = await launch({
  wsEndpoint: "wss://localhost:<SOME_PORT>",
});

// Do stuff
const page = await browser.newPage("http://example.com");
console.log(await page.evaluate(() => document.title));

// Close connection
await browser.close();

to connect to it. This should definitely be documented though, thanks for opening the issue.

lino-levan avatar Apr 30 '24 00:04 lino-levan