### Get Profiles Request Example (wget) Source: https://apidocs.nstbrowser.io/api-15554903 Example of how to make a GET request to the /profiles endpoint using wget to retrieve a list of profiles with specified query parameters. ```wget wget --header="x-api-key: " "http://localhost:8848/api/v2/profiles?page=&pageSize=&s=&tags=&groupId=&sortBy=-createdAt" ``` -------------------------------- ### Get Profiles Request Example (Java) Source: https://apidocs.nstbrowser.io/api-15554903 Example of how to make a GET request to the /profiles endpoint using Java to retrieve a list of profiles with specified query parameters. ```Java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class GetProfiles { public static void main(String[] args) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("http://localhost:8848/api/v2/profiles?page=&pageSize=&s=&tags=&groupId=&sortBy=-createdAt")) .header("x-api-key", "") .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` -------------------------------- ### Get Profiles Request Example (Swift) Source: https://apidocs.nstbrowser.io/api-15554903 Example of how to make a GET request to the /profiles endpoint using Swift to retrieve a list of profiles with specified query parameters. ```Swift import Foundation let url = URL(string: "http://localhost:8848/api/v2/profiles?page=&pageSize=&s=&tags=&groupId=&sortBy=-createdAt")! var request = URLRequest(url: url) request.httpMethod = "GET" request.setValue("", forHTTPHeaderField: "x-api-key") let task = URLSession.shared.dataTask(with: request) { data, response, error in if let error = error { print("Error: \(error)") return } if let data = data { print(String(data: data, encoding: .utf8)!) } } task.resume() ``` -------------------------------- ### StartOnceBrowser API Request Example Source: https://apidocs.nstbrowser.io/api-15554898 Example of a request body to start a browser instance with specific configurations. ```json { "name": "testProfile", "platform": "Windows", "kernelMilestone": "132" } ``` -------------------------------- ### Get Profiles Request Example (HTTPie) Source: https://apidocs.nstbrowser.io/api-15554903 Example of how to make a GET request to the /profiles endpoint using HTTPie to retrieve a list of profiles with specified query parameters. ```httpie http GET http://localhost:8848/api/v2/profiles \ page='' \ pageSize='' \ s='' \ tags='' \ groupId='' \ sortBy='-createdAt' \ "x-api-key: " ``` -------------------------------- ### Get Profiles Request Example (PowerShell) Source: https://apidocs.nstbrowser.io/api-15554903 Example of how to make a GET request to the /profiles endpoint using PowerShell to retrieve a list of profiles with specified query parameters. ```PowerShell Invoke-RestMethod -Uri "http://localhost:8848/api/v2/profiles?page=&pageSize=&s=&tags=&groupId=&sortBy=-createdAt" -Method Get -Headers @{"x-api-key"=""} ``` -------------------------------- ### Get Profiles Request Example (JavaScript) Source: https://apidocs.nstbrowser.io/api-15554903 Example of how to make a GET request to the /profiles endpoint using JavaScript to retrieve a list of profiles with specified query parameters. ```JavaScript const fetch = require('node-fetch'); const url = 'http://localhost:8848/api/v2/profiles?page=&pageSize=&s=&tags=&groupId=&sortBy=-createdAt'; const apiKey = ''; fetch(url, { method: 'GET', headers: { 'x-api-key': apiKey } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Get Profiles Response Example Source: https://apidocs.nstbrowser.io/api-15554903 Example JSON response when successfully retrieving a list of profiles. ```JSON { "code": 0, "data": { "docs": [ { "args": { "--restore-last-session": "string", "https://google.com/": "string" }, "createdAt": "string", "fingerprintId": "string", "group": { "__v": 0, "_id": "string", "createdAt": "string", "extensionIds": [ "string" ], "groupId": "string", "isDefault": true, "name": "string", "note": "string", "settings": { "args": { "--disable-backgrounding-occluded-windows": "string", "--restore-last-session": "string", "--start-maximized": "string", "https://google.com/": "string" }, "bookmarks": [ "string" ], "browserLanguage": "string", "dnsServer": "string", "startupUrls": [ "string" ], "syncCookies": true, "vault": true, "syncProfileHistoryData": true }, "status": 0, "teamId": "string", "updatedAt": "string", "userId": "string" }, "groupId": "string", "kernel": 0, "kernelMilestone": "string", "kernelVersion": "string", "lastLaunchRecord": { "createdAt": "string", "kernel": 0, "kernelCustomVersion": "string", "kernelMilestone": "string", "platform": 0, "profileId": "string", "teamId": "string", "updatedAt": "string", "userId": "string" }, "name": "string", "note": "string", "platform": 0, "platformVersion": "string", "profileId": "string", "proxyConfig": { "alias": "string", "checker": "string", "host": "string", "password": "string", "port": "string", "protocol": "string", "proxyGroupId": null, "proxyGroupName": null, "proxyId": null, "proxySetting": "string", "proxyType": "string" } } ] } } ``` -------------------------------- ### Get Profiles Request Example (cURL-Windows) Source: https://apidocs.nstbrowser.io/api-15554903 Example of how to make a GET request to the /profiles endpoint using cURL on Windows to retrieve a list of profiles with specified query parameters. ```cURL-Windows curl --location "http://localhost:8848/api/v2/profiles?page=&pageSize=&s=&tags=&groupId=&sortBy=-createdAt" \ --header "x-api-key: " ``` -------------------------------- ### Get Profiles Request Example (cURL) Source: https://apidocs.nstbrowser.io/api-15554903 Example of how to make a GET request to the /profiles endpoint using cURL to retrieve a list of profiles with specified query parameters. ```cURL curl --location 'http://localhost:8848/api/v2/profiles?page=&pageSize=&s=&tags=&groupId=&sortBy=-createdAt' \ --header 'x-api-key: ' ``` -------------------------------- ### Go HTTP Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using Go's standard HTTP package. ```go package main import ( "bytes" "fmt" "io/ioutil" "net/http" ) func main() { url := "https://api.example.com/data" requestBody := []byte(`{"key": "value"}`) resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody)) if err != nil { fmt.Printf("Error making request: %s\n", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } fmt.Printf("Status Code: %d\n", resp.StatusCode) fmt.Printf("Response Body: %s\n", string(body)) } ``` -------------------------------- ### Common Playwright Setup Source: https://apidocs.nstbrowser.io/doc-922606 This snippet demonstrates the basic setup for using Playwright with Nstbrowser. Ensure Playwright is installed via npm. The Nstbrowser client should be running and accessible. ```javascript import { chromium } from 'playwright'; async function execPlaywright(browserWSEndpoint) { try { const browser = await chromium.connectOverCDP(browserWSEndpoint); const page = await browser.newPage(); await page.goto('https://nstbrowser.io/'); await page.screenshot({path: 'screenshot.png'}); await browser.close(); } catch (err) { console.error(err); } } ``` -------------------------------- ### Shell Command Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using cURL. ```shell curl -X POST https://api.example.com/data \ -H "Content-Type: application/json" \ -d '{"key": "value"}' ``` -------------------------------- ### Python http.client Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using http.client in Python. ```python import http.client import json conn = http.client.HTTPSConnection("api.example.com") payload = json.dumps({"key": "value"}) headers = { 'Content-Type': 'application/json' } conn.request("POST", "/data", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) conn.close() ``` -------------------------------- ### C libcurl Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using libcurl in C. ```c #include #include int main(void) { CURL *curl; CURLcode res; const char *post_data = "{\"key\": \"value\"}"; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "https://api.example.com/data"); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, "Content-Type: application/json"); res = curl_easy_perform(curl); if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); curl_easy_cleanup(curl); } curl_global_cleanup(); return 0; } ``` -------------------------------- ### Java OkHttp Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using OkHttp in Java. ```java OkHttpClient client = new OkHttpClient(); MediaType JSON = MediaType.get("application/json; charset=utf-8"); String json = "{\"key\": \"value\"}"; RequestBody body = RequestBody.create(json, JSON); Request request = new Request.Builder() .url("https://api.example.com/data") .post(body) .build(); try (Response response = client.newCall(request).execute()) { System.out.println(response.body().string()); } catch (IOException e) { e.printStackTrace(); } ``` -------------------------------- ### JavaScript Native Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making a native API request in JavaScript. ```javascript const request = new Request('https://api.example.com/data', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key: 'value' }) }); fetch(request) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### PowerShell Request Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using PowerShell. ```powershell Invoke-RestMethod -Uri "https://api.example.com/data" -Method Post -ContentType "application/json" -Body '{"key": "value"}' ``` -------------------------------- ### OCaml Cohttp Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using Cohttp in OCaml. ```ocaml let () = Lwt_main.run @@ object method run = let headers = Cohttp.Header.init () in let headers = Cohttp.Header.add headers "Content-Type" "application/json" in let body = "{\"key\": \"value\"}" in let uri = Uri.of_string "https://api.example.com/data" in Cohttp_lwt_unix.Client.post ~headers ~body uri >>= fun (resp, body) -> Cohttp_lwt.Body.to_string body >|= fun body_str -> Printf.printf "%s\n" body_str; Lwt.return_unit end #require "cohttp.lwt-unix";; ``` -------------------------------- ### JavaScript Request Library Example Source: https://apidocs.nstbrowser.io/api-15554903 Example of making a POST request using the 'request' library in JavaScript. This library simplifies HTTP requests. ```javascript const request = require('request'); request.post({ url: 'http://example.com/api/resource', json: { key: 'value' } }, (error, response, body) => { if (error) { console.error('Error:', error); return; } console.log('Status Code:', response.statusCode); console.log('Response Body:', body); }); ``` -------------------------------- ### Swift URLSession Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using URLSession in Swift. ```swift let url = URL(string: "https://api.example.com/data")! var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type") let jsonData = try? JSONSerialization.data(withJSONObject: ["key": "value"]) request.httpBody = jsonData let task = URLSession.shared.dataTask(with: request) { data, response, error in guard let data = data, error == nil else { print(error?.localizedDescription ?? "Unknown error") return } if let httpResponse = response as? HTTPURLResponse { print("Status code: \(httpResponse.statusCode)") } if let responseString = String(data: data, encoding: .utf8) { print(responseString) } } task.resume() ``` -------------------------------- ### JavaScript Unirest Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using Unirest in JavaScript. ```javascript const unirest = require('unirest'); unirest('POST', 'https://api.example.com/data') .headers({'Content-Type': 'application/json'}) .send(JSON.stringify({ key: 'value' })) .end(function (res) { if (res.error) throw new Error(res); console.log(res.body); }); ``` -------------------------------- ### CreateProfile Request Body Example Source: https://apidocs.nstbrowser.io/api-15554904 Example of a request body to create a profile with custom settings. This includes name, platform, kernel milestone, group name, proxy, and notes. ```yaml openapi: 3.0.1 info: title: '' description: '' version: 1.0.0 paths: /profiles: post: summary: CreateProfile deprecated: false description: >- create profile with random fingerprint, you can also custom browser fingerprints by body parameter `fingerprint` tags: - API/Profiles - v2/Profiles parameters: [] requestBody: content: application/json: schema: type: object properties: name: description: 'profile name, default value: `nst_${timestamp}`' type: string examples: - Profile platform: description: >- fingerprint os platform, default value: it's `Windows` on windows otherwise `macOS` type: string enum: - Windows - macOS - Linux examples: - Windows kernelMilestone: type: string description: 'kernelMilestone, default value: the latest published version' enum: - '132' - '135' - '138' - '140' x-apidog-enum: - value: '132' name: '' description: '' - value: '135' name: '' description: '' - value: '138' name: '' description: '' - value: '140' name: '' description: '' examples: - '140' groupId: description: profile group id, higher priority than `groupName` type: string examples: - 1e455935-3e3e-4e3e-8e3e-3e3e3e3e3e3e groupName: description: an existing group name type: string examples: - Default proxy: description: profile proxy, higher priority than `proxyGroupName` type: string examples: - http://username:password@ip:port builtinProxy: $ref: '#/components/schemas/nstbrowser.BuiltinProxy' description: >- nstbrowser builtin proxy options, supported in `v1.19.0+`, the priority is higher than the `proxy` parameter, please make sure you have enought credits proxyGroupName: description: an existing proxy group name type: string note: description: profile note type: string fingerprint: description: fingerprints allOf: - $ref: '#/components/schemas/agent.LaunchFingerprint' startupUrls: description: browser startup urls type: array items: type: string args: description: custom args with kernel command line switches type: object additionalProperties: type: string x-apifox-orders: [] properties: {} x-apifox-ignore-properties: [] x-apidog-orders: [] x-apidog-ignore-properties: [] x-apifox-refs: {} x-apifox-orders: - name - platform - kernelMilestone - groupId - groupName - proxy - proxyGroupName - note - fingerprint - startupUrls - args x-apifox-ignore-properties: [] x-apidog-orders: - name - platform - kernelMilestone - groupId - groupName - proxy - builtinProxy - proxyGroupName - note - fingerprint - startupUrls - args x-apidog-ignore-properties: [] example: name: testProfile platform: Windows kernelMilestone: '132' groupName: Default note: test profile note proxy: http://admin:123456@127.0.0.1:8000 ``` -------------------------------- ### JavaScript Axios Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using Axios in JavaScript. ```javascript axios.post('https://api.example.com/data', { key: 'value' }, { headers: { 'Content-Type': 'application/json' } }) .then(response => { console.log(response.data); }) .catch(error => { console.error(error); }); ``` -------------------------------- ### JavaScript Fetch API Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using the Fetch API in JavaScript. ```javascript fetch('https://api.example.com/data', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key: 'value' }) }) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Dart Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using Dart's http package. ```dart import 'package:http/http.dart' as http; import 'dart:convert'; Future postData() async { final url = Uri.parse('https://api.example.com/data'); final response = await http.post( url, headers: { 'Content-Type': 'application/json; charset=UTF-8', }, body: jsonEncode({ 'key': 'value', }), ); if (response.statusCode == 200) { print('Response: ${response.body}'); } else { print('Request failed with status: ${response.statusCode}'); } } void main() { postData(); } ``` -------------------------------- ### JavaScript Request Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using the 'request' library in JavaScript. ```javascript const request = require('request'); const options = { url: 'https://api.example.com/data', method: 'POST', json: true, body: { key: 'value' } }; request(options, function (error, response, body) { if (error) { console.error(error); } else { console.log(body); } }); ``` -------------------------------- ### R RCurl Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using the RCurl package in R. ```r library(RCurl) library(RJSONIO) url <- "https://api.example.com/data" post_data <- toJSON(list(key = "value")) headers <- c('Content-Type' = 'application/json') result <- postForm( தரவு = post_data, .url = url, .opts = list(httpheader = headers, ssl.verify.peer = FALSE)) cat(result) ``` -------------------------------- ### StartOnceBrowser Source: https://apidocs.nstbrowser.io/api-19974738 Starts a browser instance that will automatically stop after a single use. ```APIDOC ## POST /browsers/once ### Description Starts a browser instance that is intended for a single operation and will automatically terminate afterward. ### Method POST ### Endpoint /browsers/once ### Response #### Success Response (200) - **browserId** (string) - The ID of the started browser instance. #### Response Example { "browserId": "single-use-browser-id" } ``` -------------------------------- ### Ruby Net::HTTP Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using Net::HTTP in Ruby. ```ruby require 'net/http' require 'uri' require 'json' uri = URI.parse("https://api.example.com/data") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true # if you are using HTTPS request = Net::HTTP::Post.new(uri.request_uri) request['Content-Type'] = 'application/json' request.body = JSON.dump({"key" => "value"}) response = http.request(request) puts response.body ``` -------------------------------- ### R httr Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using the httr package in R. ```r library(httr) library(jsonlite) url <- "https://api.example.com/data" body <- toJSON(list(key = "value"), auto_unbox = TRUE) response <- POST(url, body = body, encode = "json", add_headers(.headers = c('Content-Type' = 'application/json'))) content(response, "parsed") ``` -------------------------------- ### POST /browser/launch Source: https://apidocs.nstbrowser.io/api-15554921 Launches a new browser instance with specified configurations. This endpoint allows for detailed customization of browser profiles, including proxy settings, fingerprinting, and startup URLs. ```APIDOC ## POST /browser/launch ### Description Launches a new browser instance with specified configurations. This endpoint allows for detailed customization of browser profiles, including proxy settings, fingerprinting, and startup URLs. ### Method POST ### Endpoint /browser/launch ### Parameters #### Request Body - **name** (string) - Required - The name of the browser profile. - **platform** (string) - Optional - The operating system platform (e.g., Windows, macOS, Linux). - **kernel** (string) - Optional - The browser kernel to use (e.g., Chrome, Firefox). - **kernelMilestone** (string) - Optional - The specific milestone version of the kernel. - **autoClose** (boolean) - Optional - Whether to automatically close the browser instance. - **timedCloseSec** (integer) - Optional - The number of seconds after which to automatically close the browser. - **clearCacheOnClose** (boolean) - Optional - Whether to clear the cache when the browser closes. - **fingerprintRandomness** (integer) - Optional - Controls the randomness of fingerprinting. - **headless** (boolean) - Optional - Whether to run the browser in headless mode. - **incognito** (boolean) - Optional - Whether to run the browser in incognito mode. - **proxy** (string) - Optional - The proxy server URL (e.g., http://admin:123456@127.0.0.1:8000). - **builtinProxy** (string) - Optional - Built-in proxy configuration. - **remoteDebuggingPort** (integer) - Optional - The port for remote debugging. - **skipProxyChecking** (boolean) - Optional - Whether to skip proxy checking. - **startupUrls** (array of strings) - Optional - A list of URLs to open on startup. - **urlBlockList** (array of strings) - Optional - A list of URLs to block. - **urlAllowList** (array of strings) - Optional - A list of URLs to allow. - **fingerprint** (object) - Optional - Fingerprint configuration. - **deviceMemory** (integer) - Optional - Device memory in GB (e.g., 2, 4, 8). - **disableImageLoading** (boolean) - Optional - Disable image loading. - **doNotTrack** (boolean) - Optional - Enable Do Not Track. - **flags** (object) - Optional - Fingerprint flags. - **fonts** (array of strings) - Optional - List of fonts to use. - **geolocation** (object) - Optional - Geolocation settings. - **hardwareConcurrency** (integer) - Optional - Number of CPU cores. - **restoreLastSession** (boolean) - Optional - Restore last session. - **userAgent** (string) - Optional - The user agent string. - **webrtc** (object) - Optional - WebRTC configuration. - **args** (object) - Optional - Additional command-line arguments for the browser. ### Request Example { "name": "testProfile", "platform": "Windows", "kernel": "Chrome", "kernelMilestone": "132", "autoClose": true, "timedCloseSec": 30, "clearCacheOnClose": true, "groupName": "Default", "headless": false, "incognito": true, "note": "test profile note", "proxy": "http://admin:123456@127.0.0.1:8000", "skipProxyChecking": true, "fingerprint": { "flags": { "audio": "Noise", "battery": "Masked", "canvas": "Noise", "clientRect": "Noise", "fonts": "Masked", "geolocation": "Custom", "geolocationPopup": "Prompt", "gpu": "Allow", "localization": "Custom", "screen": "Custom", "speech": "Masked", "timezone": "Custom", "webgl": "Noise", "webrtc": "Custom" }, "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.6998.45 Safari/537.36", "deviceMemory": 8, "hardwareConcurrency": 16, "disableImageLoading": true, "restoreLastSession": true, "doNotTrack": true, "localization": { "language": "zh-HK", "languages": [ "zh-HK", "en-US", "en" ], "timezone": "Asia/Hong_Kong" }, "screen": { "width": 1280, "height": 1024 }, "geolocation": { "latitude": "31.2333", "longitude": "121.469", "accuracy": "603" }, "webrtc": { "publicIp": "111.111.111.111" } }, "startupUrls": [ "https://www.nstbrowser.io" ], "args": { "--remote-debugging-port": 34543, "disable-backgrounding-occluded-windows": true } } ### Response #### Success Response (200) - **browser_id** (string) - The unique identifier for the launched browser instance. - **remote_debugging_address** (string) - The address for remote debugging. #### Response Example { "browser_id": "some-browser-id", "remote_debugging_address": "ws://127.0.0.1:34543/devtools/browser/some-browser-guid" } ``` -------------------------------- ### Create and Connect to a New Browser Instance Source: https://apidocs.nstbrowser.io/doc-922602 This function creates a new browser profile based on provided configurations and launches it, then connects to it. It supports various settings including platform, kernel milestone, proxy, and fingerprinting. The browser will be launched in headless mode by default and will auto-close. ```python import json from urllib.parse import quote from urllib.parse import urlencode # create_and_connect_to_browser: launch new browser and connect # Create a new Profile based on config and launch the browser # Support custom config def create_and_connect_to_browser(): host = '127.0.0.1' api_key = 'your apiKey' config = { 'name': 'testProfile', 'platform': 'windows', # support: windows, macos, linux 'kernelMilestone': '132', 'once': True, 'headless': True, # support: true or false 'autoClose': True, 'remoteDebuggingPort': 9222, 'proxy': '', # input format: schema://user:password@host:port eg: http://user:password@localhost:8080 'fingerprint': { 'hardwareConcurrency': 16, 'deviceMemory': 8, } } query = urlencode({ 'x-api-key': api_key, # required 'config': quote(json.dumps(config)) }) url = f'http://{host}:8848/api/v2/connect?{query}' print('devtool url: ' + url) port = get_debugger_port(url) debugger_address = f'{host}:{port}' print("debugger_address: " + debugger_address) exec_selenium(debugger_address) create_and_connect_to_browser() ``` -------------------------------- ### StartOnceBrowser Source: https://apidocs.nstbrowser.io/api-15554898 Starts a single browser instance with specified configurations. This endpoint is useful for launching a browser for a specific task or session. ```APIDOC ## POST /browsers/once ### Description Starts a single browser instance with specified configurations. ### Method POST ### Endpoint /browsers/once ### Parameters #### Request Body - **name** (string) - Optional - profile name, default value: `nst_${timestamp}` - **platform** (string) - Optional - fingerprint os platform, default value: it's `Windows` on windows otherwise `macOS`. Enum: `Windows`, `macOS`, `Linux` - **kernelMilestone** (string) - Optional - kernelMilestone, default value: the latest published version. Enum: `'128'`, `'130'`, `'132'` - **autoClose** (boolean) - Optional - indicates autoclose browser after finished - **timedCloseSec** (integer) - Optional - indicates autoclose browser after specified seconds - **fingerprintRandomness** (boolean) - Optional - more random fingerprints - **headless** (string) - Optional - **incognito** (boolean) - Optional - incognito mode - **remoteDebuggingPort** (integer) - Optional - browser port - **proxy** (string) - Optional - profile proxy, higher priority than proxyGroupName - **builtinProxy** (object) - Optional - nstbrowser builtin proxy options, supported in `v1.19.0+`, the priority is higher than the `proxy` parameter, please make sure you have enought credits - **skipProxyChecking** (boolean) - Optional - indicates skip proxy checking when launch profile,`Based On IP` flagged fingerprints will take on your local IP rather than your proxy IP - **args** (object) - Optional - custom args with kernel command line switches - **startupUrls** (array) - Optional - startup urls - **fingerprint** (object) - Optional - custom fingerprint ### Request Example { "example": "{\"name\": \"testProfile\", \"platform\": \"Windows\", \"kernelMilestone\": \"132\"}" } ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example { "example": "response body" } ``` -------------------------------- ### Create Profile Source: https://apidocs.nstbrowser.io/api-15554904 Creates a new profile with specified fingerprint and startup URLs. ```APIDOC ## POST /profiles ### Description Creates a new profile with specified fingerprint and startup URLs. ### Method POST ### Endpoint /profiles ### Request Body - **fingerprint** (object) - Required - Fingerprint details for the profile. - **flags** (object) - Required - Flags for various fingerprint aspects. - **audio** (string) - Optional - Audio flag (e.g., 'Noise'). - **battery** (string) - Optional - Battery flag (e.g., 'Masked'). - **canvas** (string) - Optional - Canvas flag (e.g., 'Noise'). - **clientRect** (string) - Optional - ClientRect flag (e.g., 'Noise'). - **fonts** (string) - Optional - Fonts flag (e.g., 'Masked'). - **geolocation** (string) - Optional - Geolocation flag (e.g., 'Custom'). - **geolocationPopup** (string) - Optional - Geolocation popup flag (e.g., 'Prompt'). - **gpu** (string) - Optional - GPU flag (e.g., 'Allow'). - **localization** (string) - Optional - Localization flag (e.g., 'Custom'). - **screen** (string) - Optional - Screen flag (e.g., 'Custom'). - **speech** (string) - Optional - Speech flag (e.g., 'Masked'). - **timezone** (string) - Optional - Timezone flag (e.g., 'Custom'). - **webgl** (string) - Optional - WebGL flag (e.g., 'Noise'). - **webrtc** (string) - Optional - WebRTC flag (e.g., 'Custom'). - **userAgent** (string) - Required - The user agent string. - **deviceMemory** (integer) - Optional - Device memory in GB (e.g., 8). - **hardwareConcurrency** (integer) - Optional - Number of logical CPU cores (e.g., 16). - **disableImageLoading** (boolean) - Optional - Whether to disable image loading. - **restoreLastSession** (boolean) - Optional - Whether to restore the last session. - **doNotTrack** (boolean) - Optional - Whether Do Not Track is enabled. - **localization** (object) - Optional - Localization settings. - **language** (string) - Optional - The primary language (e.g., 'zh-HK'). - **languages** (array) - Optional - List of supported languages. - (string) - **timezone** (string) - Optional - The timezone (e.g., 'Asia/Hong_Kong'). - **screen** (object) - Optional - Screen dimensions. - **width** (integer) - Optional - Screen width in pixels. - **height** (integer) - Optional - Screen height in pixels. - **geolocation** (object) - Optional - Geolocation coordinates. - **latitude** (string) - Optional - Latitude value (e.g., '31.2333'). - **longitude** (string) - Optional - Longitude value (e.g., '121.469'). - **accuracy** (string) - Optional - Accuracy in meters (e.g., '603'). - **webrtc** (object) - Optional - WebRTC information. - **publicIp** (string) - Optional - Public IP address (e.g., '111.111.111.111'). - **startupUrls** (array) - Required - List of URLs to open on startup. - (string) ### Response #### Success Response (200) - **description** (string) - OK #### Response Example { "example": "response body" } ``` -------------------------------- ### Run Nstbrowser Docker Container Source: https://apidocs.nstbrowser.io/doc-922611 This command starts a container, mapping the necessary port and setting the API token. Replace 'xxx' with your actual API key obtained from the Nstbrowser website. ```shell docker run -it \ -e TOKEN=xxx \ -p 8848:8848 \ --name nstbrowserless \ nstbrowser/browserless:latest ``` -------------------------------- ### Launch and Connect to an Existing Browser Instance Source: https://apidocs.nstbrowser.io/doc-922602 This function launches a specified browser profile and connects to it using the Nstbrowser API. It supports custom configurations like headless mode and auto-close behavior. Ensure the Nstbrowser client is running and accessible. ```python import json from urllib.parse import quote from urllib.parse import urlencode # launch_and_connect_to_browser: Launch the specified browser and connect # You need to create the corresponding profile in advance # Support custom config def launch_and_connect_to_browser(profile_id: str): host = '127.0.0.1' api_key = 'your apiKey' config = { 'headless': False, # support: true or false 'autoClose': True, } query = urlencode({ 'x-api-key': api_key, # required 'config': quote(json.dumps(config)) }) url = f'http://{host}:8848/api/v2/connect/{profile_id}?{query}' print('devtool url: ' + url) port = get_debugger_port(url) debugger_address = f'{host}:{port}' print("debugger_address: " + debugger_address) exec_selenium(debugger_address) launch_and_connect_to_browser('your profileId') ``` -------------------------------- ### Objective-C NSURLSession Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using NSURLSession in Objective-C. ```objective-c #import int main(int argc, const char * argv[]) { @autoreleasepool { NSURL *url = [NSURL URLWithString:@"https://api.example.com/data"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; request.HTTPMethod = @"POST"; [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; NSDictionary *params = @{@"key": @"value"}; NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; request.HTTPBody = jsonData; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { NSLog(@"Error: %@\n", error.localizedDescription); return; } NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"Response: %@\n", responseString); }]; [task resume]; // Keep the main thread alive to allow the network request to complete CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, YES); } return 0; } ``` -------------------------------- ### StartBrowser Source: https://apidocs.nstbrowser.io/api-15554899 Starts a browser instance for a given profile. This operation allows you to initiate a new browser session that can be controlled remotely. ```APIDOC ## POST /browsers/{profileId} ### Description Start browser ### Method POST ### Endpoint /browsers/{profileId} ### Parameters #### Path Parameters - **profileId** (string) - Required - profileId ### Response #### Success Response (200) - **code** (integer) - - **data** (object) - - **err** (boolean) - - **msg** (string) - #### Response Example { "code": 0, "data": { "port": 12345, "profileId": "example_profile_id", "proxy": "http://localhost:8080", "webSocketDebuggerUrl": "ws://localhost:12345/devtools/page/abcdef" }, "err": false, "msg": "Success" } ``` -------------------------------- ### C# RestSharp Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using RestSharp in C#. ```csharp using RestSharp; using System; public class Example { public static void Main(string[] args) { var client = new RestClient("https://api.example.com"); var request = new RestRequest("data", Method.Post); request.AddHeader("Content-Type", "application/json"); request.AddJsonBody(new { key = "value" }); try { var response = client.Execute(request); Console.WriteLine(response.Content); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } ``` -------------------------------- ### StartBrowser Source: https://apidocs.nstbrowser.io/llms.txt Starts a single browser instance. This API is part of the Browsers collection. ```APIDOC ## StartBrowser ### Description Starts a single browser instance. ### Method POST ### Endpoint /api/v1/browser/start ### Parameters #### Request Body - **fingerprint** (string) - Optional - Custom browser fingerprints. - **proxy** (object) - Optional - Proxy configuration for the browser. - **url** (string) - Optional - Proxy URL. - **protocol** (string) - Optional - Proxy protocol. - **host** (string) - Optional - Proxy host. - **port** (integer) - Optional - Proxy port. - **args** (array) - Optional - Additional browser arguments. - **profileId** (string) - Optional - The ID of the profile to use. - **mode** (string) - Optional - The mode to start the browser in (e.g., 'normal', 'incognito'). ``` -------------------------------- ### Go HTTP Request Source: https://apidocs.nstbrowser.io/api-15554903 Example of making a POST request using Go's standard HTTP package. This is a common way to handle HTTP requests in Go. ```go package main import ( "bytes" "fmt" "io/ioutil" "net/http" ) func main() { url := "http://example.com/api/resource" jsonBody := []byte(`{"key":"value"}`) bodyReader := bytes.NewReader(jsonBody) req, err := http.NewRequest("POST", url, bodyReader) if err != nil { fmt.Printf("Error creating request: %s\n", err) return } req.Header.Set("Content-Type", "application/json") client := &http.Client{} resp, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %s\n", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Printf("Error reading response body: %s\n", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### PHP Guzzle Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using Guzzle in PHP. ```php request('POST', 'https://api.example.com/data', [ 'json' => ['key' => 'value'] ]); echo $response->getBody()->getContents(); } catch (\GuzzleHttp\Exception\GuzzleException $e) { echo 'Error: ' . $e->getMessage(); } ?> ``` -------------------------------- ### PHP pecl_http Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using pecl_http in PHP. ```php 'value']); $options = [ 'method' => 'POST', 'header' => "Content-Type: application/json\r\nContent-Length: " . strlen($data) . "\r\n", 'content' => $data ]; $context = stream_context_create(['http' => $options]); $result = file_get_contents($url, false, $context); if ($result === false) { echo 'Error fetching data'; } else { echo $result; } ?> ``` -------------------------------- ### PHP HTTP_Request2 Example Source: https://apidocs.nstbrowser.io/api-19974738 Example of making an API request using HTTP_Request2 in PHP. ```php setMethod(HTTP_Request2::METHOD_POST); $request->setHeader('Content-Type', 'application/json'); $request->setBody(json_encode(['key' => 'value'])); $response = $request->send(); echo $response->getBody(); } catch (HTTP_Request2_Exception $e) { echo 'Error: ' . $e->getMessage(); } ?> ``` -------------------------------- ### StartBrowsers Source: https://apidocs.nstbrowser.io/api-15554897 Starts browsers, optionally in headless mode. It accepts a list of profile IDs in the request body. ```APIDOC ## POST /browsers ### Description Start browsers, optionally in headless mode. It accepts a list of profile IDs in the request body. ### Method POST ### Endpoint /browsers ### Parameters #### Query Parameters - **headless** (string) - Optional - true or false, whether launch in headless mode #### Request Body - **profileIds** (array of strings) - Required - A list of profile IDs to start browsers with. ### Request Example ```json { "profileIds": [ "profile1", "profile2" ] } ``` ### Response #### Success Response (200) - **code** (integer) - The status code of the operation. - **data** (string) - The data returned by the operation. - **err** (boolean) - Indicates if an error occurred. - **msg** (string) - A message describing the result of the operation. #### Response Example ```json { "code": 0, "data": "Browsers started successfully.", "err": false, "msg": "OK" } ``` ``` -------------------------------- ### StartBrowsers Source: https://apidocs.nstbrowser.io/llms.txt Starts multiple browser instances. This API is part of the Browsers collection. ```APIDOC ## StartBrowsers ### Description Starts multiple browser instances. ### Method POST ### Endpoint /api/v1/browser/starts ### Parameters #### Request Body - **browsers** (array) - Required - An array of browser configurations. - Each element is an object with the same properties as `StartBrowser`'s request body. ```