TL;DR
A browser automation API for profile management controls browser environments and their lifecycle, while an automation framework performs page-level work. Keeping these roles separate makes failures easier to diagnose. Your application should know whether it failed to start an environment, connect to the browser, load a page, or satisfy a business condition.
For example, an authorized catalog QA task might select an existing Profile, launch it, inspect a page title, and stop it. Creating a new Profile for every retry would introduce unnecessary state. Deleting a Profile after each check would be inappropriate when the workflow depends on persistent account data.
Represent the lifecycle as explicit states: prepared, launching, running, attached, verified, and stopped. Store the Profile ID as the stable identifier for the task. Keep the environment's saved configuration separate from temporary debugging endpoints returned for a running browser.
| Operation | Role in the workflow | Validation |
|---|---|---|
| Create or select Profile | Establish the intended environment | Confirm ownership, group, and configuration |
| Launch saved Profile | Start a browser for that environment | Check response status and returned data |
| Read connection details | Locate the running browser | Use the current response, not a cached URL |
| Attach framework | Control pages | Check connection and context selection |
| Stop browser | End this execution | Confirm the browser is stopped |
The API v2 introduction gives the default HTTP base as http://localhost:8848/api/v2. The client or container must be reachable from the process making the request. A container's localhost identifies that container, so deployment topology matters.
Select a Profile you are authorized to run and record its actual ID. For inventory traversal, the GetProfilesByCursor documentation is the current starting point. Do not invent pagination parameters from another vendor's API, and do not assume the first record returned is the intended environment.
Use the documented launch and stop routes with the same Profile ID, and validate both the transport and application result. The following standard-library Python example deliberately demonstrates lifecycle management only. It does not create profiles, collect private data, or claim that a successful launch completes a website task.
Start the Nstbrowser client or your configured Docker service, sign in as required, generate an API Key, and choose a non-production Profile. Set NST_API_KEY and NST_PROFILE_ID through your local environment or secret-management workflow. The default base is suitable only when the Python process can reach that same machine's service.
This example has not been authenticated against a live Nstbrowser Profile because a reachable local service and test credentials were unavailable.
The StartBrowser endpoint uses POST on /browsers/{profileId}. Its returned data includes webSocketDebuggerUrl. Stopping uses DELETE on that browser route, as documented by StopBrowser.
import json
import os
from urllib.error import HTTPError, URLError
from urllib.parse import quote
from urllib.request import Request, build_opener, ProxyHandler
key = os.environ["NST_API_KEY"]
profile_id = quote(os.environ["NST_PROFILE_ID"], safe="")
base = "http://localhost:8848/api/v2"
opener = build_opener(ProxyHandler({})) # Local service only.
def call(method, path):
request = Request(base + path, method=method,
headers={"x-api-key": key, "Accept": "application/json"})
try:
with opener.open(request, timeout=30) as response:
result = json.load(response)
except HTTPError as error:
raise RuntimeError(f"HTTP failure: {error.code}") from None
except URLError:
raise RuntimeError("Local API connection failed") from None
if not isinstance(result, dict) or result.get("code") != 0:
raise RuntimeError("API returned an unsuccessful application result")
return result.get("data")
path = f"/browsers/{profile_id}"
started = False
try:
data = call("POST", path)
started = True
if not isinstance(data, dict) or not data.get("webSocketDebuggerUrl"):
raise RuntimeError("Launch response did not include a debugger URL")
# Pass this URL directly to your supported automation framework.
# Do not publish the URL or assume a website task has completed.
debugger_url = data["webSocketDebuggerUrl"]
print("Launch confirmed; debugger URL received")
finally:
if started:
call("DELETE", path)
print("Browser stop confirmed")
This sample closes the browser immediately after checking connection data. Add your framework operation inside the try block when you have validated the lifecycle. If a launch request times out, inspect running browsers before retrying: the server may have started the browser even though your process did not receive a response. The script cannot resolve that ambiguous state automatically.
For Chromium workflows, Playwright documents connectOverCDP. It also notes limitations compared with a native Playwright protocol connection. Confirm that the attached context is the intended environment before creating or selecting a page. Use locators based on meaningful page attributes and check a visible result after each important operation.
Treat an HTTP response and a JSON response as separate evidence. HTTP status codes describe request-level outcomes; your application must also validate the API's documented result and expected data.
Nstbrowser exposes a documented API for managing saved environments and running browsers. API v2 supports both the client and Docker deployment paths. Returned debugging information provides a handoff from environment management to page automation. That separation helps teams reuse existing environments without rebuilding their complete browser-control layer. It is useful when your workflow needs explicit lifecycle control and a clear place to validate each stage.
Record operation name, Profile ID, timestamp, request duration, and a redacted error classification. Avoid logging API keys, cookies, or raw debugger URLs. Retry only after checking whether the previous operation changed state. Apply a workload limit based on measured resources and current service allowances instead of launching every available Profile at once.
Begin with a single authorized test environment. Once launch, page inspection, and cleanup are independently verified, add task scheduling and broader inventory handling.
Q: Is a Profile management API the same as an MCP server?
No. An HTTP API does not establish that an MCP server exists. This guide describes the documented API and framework connection path.
Q: Does browser startup prove the target website loaded?
No. Startup, framework attachment, navigation, and the website's final success condition require separate checks.
Q: Does stopping the browser delete its Profile?
No. Stopping a running browser and deleting a saved Profile are separate operations. Choose cleanup behavior according to the intended persistence model.
Q: Was the lifecycle example executed against a real account?
No. A reachable local service and test credentials were unavailable, so authenticated execution and framework attachment remain prerequisites to validate in your environment.