Node.js quickstart
-
Install
Terminal window npm install rayobrowse playwrightNode.js 18 or newer. The samples are ES modules with top-level
await: save them as.mjsfiles, or add"type": "module"to yourpackage.json. -
Launch a browser
// Save as quickstart.mjs and run: node quickstart.mjsimport { Rayobrowse } from 'rayobrowse';import { chromium } from 'playwright';const client = new Rayobrowse({endpoint: 'https://browser.rayobyte.com',apiKey: 'rb_live_YOUR_KEY',});const wsUrl = await client.connectUrl({ os: 'windows', proxy: PROXY });try {const browser = await chromium.connectOverCDP(wsUrl);const context = browser.contexts()[0];const page = context.pages()[0] ?? (await context.newPage());await page.goto('https://quotes.toscrape.com/');console.log(await page.title()); // Quotes to Scrapeawait browser.close();} finally {await client.close();}endpointis the gateway you are calling and belongs on every client you build. Leaveproxyout andconnectUrl()throwsBrowserCreateErrorwithstatusCode400 and a plain-textbodythat startsA proxy is required for this account.client.close()infinallyends the session even when the page load throws. Playwright’sbrowser.close()only detaches from a browser it did not launch. -
Watch it run
Add
vnc: trueto the same call and read the live-view URL off the client:const liveUrl = await client.connectUrl({ os: 'windows', proxy: PROXY, vnc: true });console.log(client.vncUrl); -
Handle the limits
import { AuthError, ConcurrencyLimitError, RateLimitError } from 'rayobrowse';try {const wsUrl = await client.connectUrl({ os: 'windows', proxy: PROXY });} catch (err) {if (err instanceof AuthError) {console.error('Key rejected');} else if (err instanceof ConcurrencyLimitError || err instanceof RateLimitError) {// 5 s for a full account, 60 s for the rate limitawait new Promise((r) => setTimeout(r, err.retryAfter * 1000));} else {throw err;}}A
429, too many running browsers or too many creates in a minute, throws one of these two, both withstatusCode429. Catch both: in 0.2.0 the class does not reliably say which limit was hit.retryAftercomes from theretry-afterheader and is right for either.
await client.close() closes the most recent session, or the id you pass it.
Skip it and the browser runs until maxLifetime, 7,200 seconds by default, and
all of it counts against your browser hours.
Next: Node.js reference and Limits.
Was this page helpful?
Thanks — that helps us fix it.