surfsky package uses ES modules and includes TypeScript definitions.
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 asfirst-browser.mjs and run node first-browser.mjs. The same code can be used in a TypeScript project configured for ESM.
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:
try/finally or a TypeScript build that transforms await using for your runtime.
Interact with the page
Methods includegoto, 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: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:
Running many browsers
Proxies
Passproxy to browser() or session():
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:
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.