Skip to main content
Requires Node.js 22 or newer, or Bun. The surfsky package uses ES modules and includes TypeScript definitions.
Set SURFSKY_API_TOKEN and SURFSKY_API_BASE_URL from the dashboard. See credential setup. You can also pass apiToken and baseUrl to the constructor.

Start a browser

Save as first-browser.mjs and run node first-browser.mjs. The same code can be used in a TypeScript project configured for ESM.
Expected output is Example Domain. browser.close() stops the session. Put it in finally so it also runs when a page operation throws. Cleanup cannot complete if the process is forcibly terminated or loses access to the API. On runtimes that support explicit resource management, such as Node.js 24+ or Bun, await using can handle cleanup at scope exit:
For Node.js 22, use try/finally or a TypeScript build that transforms await using for your runtime.

Interact with the page

Methods include goto, click, type, hover, innerText, and waitForSelector. Run page operations while the browser is open, using selectors from your target page:
evaluate() runs JavaScript in an isolated execution context by default. Use isolated: false to access variables defined by the page. DOM changes remain visible to the page.

Save traffic

Choose resource types when starting a browser:
Close this browser after use. Keep resources required by your target page; see Speed optimization.

Capture a page’s API response

Start capture before navigation. Adapt the URL and response path to your application:

Multiple tabs

browser operates on the first tab. browser.pages contains other tabs and popups:
See the session page limit.

Running many browsers

The pool collects an outcome for each job and can reuse browsers between jobs. Leases retain browser state, including cookies. Do not assume each item receives an empty browser. For manual leasing on Node.js 24+ or Bun:
See Concurrency for account limits and work distributed across processes.

Proxies

Pass proxy to browser() or session():
You can also select tier: "shared" or supply a proxy URL. Close the browser after use. client.proxies provides location and quota lookups; see Proxies.

Sessions

By default, client.browser() starts a one-time session whose state is discarded when it stops. To reuse login state, cookies, and local storage across runs, create a persistent profile and pass its UUID to client.browser({ profileUuid }). Save this as reuse-session.mjs. On the first run it creates a profile and saves its UUID in profile-uuid.txt. Later runs read that UUID and restore the same profile:
Run node reuse-session.mjs twice from the same directory, waiting for each run to finish. The first run prints Previous run: null; the second prints Previous run: saved. Surfsky stores the browser state; the local file stores only the profile UUID. await browser.close() stops the session and saves the selected browser state. To reuse a login, replace the example page operations with your site’s sign-in flow on the first run, then open an authenticated page on later runs.

Raw requests

request() returns the raw response and does not throw on HTTP status. The SDK repository contains the complete method reference and examples.