SDK Reference
Dive deeper into the Nfig SDK capabilities
Initialization
To initialize the SDK,create an instance of NfigClient with your API key. This connects your application to Nfig and allows interaction with the platform. During initialization, you can also specify the preferred browser mode (LOCAL or REMOTE) and enable debug mode to assist with troubleshooting.
Parameter | Type | Description |
---|---|---|
apiKey | string | required. Your API key from the Nfig Portal. |
browserMode | ”LOCAL” | “REMOTE” | optional. Specifies the browser mode. Defaults to REMOTE. |
debug | boolean | optional. Enables debug logging if set to true. |
Session Management
Note: A managed session in Nfig is active for 15 minutes in remote mode.
Creating a session
Use the createSession method to initialize a session.
REMOTE Mode: Automate actions in a remote browser environment.Returns a preview URL for live monitoring.
LOCAL Mode: Automate actions in a locally installed browser instance. Only supports Playwright for now.Allows passing the Page context initially, making it available throughout the session, or you can pass it with each method call.
Usage Example: REMOTE Mode
Usage Example: LOCAL Mode
CreateSessionOptions
Parameter | Type | Description |
---|---|---|
currentPage | Page | optional (LOCAL mode only). The Playwright Page instance to be used for the session. |
Ending a Session
EndSessionResponse
Field | Type | Description |
---|---|---|
success | boolean | Indicates if the session was ended successfully. |
message | string | Informational message about the session termination. |
Note: Ending a session is a necessary action to avoid unexpected billing.
Prompting
LOCAL mode can only take 1 precious action at a time.
Below is an example showing an Airbnb workflow using both modes.
Usage example: LOCAL mode
Usage example: REMOTE mode
SDK Methods
Act method
act method performs specific actions on a webpage.
Basic usage
Fallback Method
In LOCAL mode, act supports fallback method to try an action manually and use agent as a fallback method.
Parameters
Parameter | Type | Description |
---|---|---|
goal | string | required. A descriptive goal for the action to be performed. |
options | Object | optional. Additional options to customize the action. |
Options
Property | Type | Description |
---|---|---|
currentPage | Page(playwright) | optional (LOCAL mode only). The Playwright Page instance. |
execute | boolean | optional. If set to false, the action will not be executed locally. Defaults to true. |
action | ”click” | “type” | “navigate” | “wait” | optional. Action is supported only on LOCAL mode. If the perfoming action is failed, it will be switched to agent mode. |
selector | string | optional (For click and type action only). CSS selector of the element to type into. |
iterCount | number | optional (For click action only). Number of times to perform the click action. |
inputText | string | optional (for type action only). CSS selector of the element to type into. |
enter | boolean | optional (for type action only). If set to true, simulates pressing the Enter key after typing. |
url | string | optional. URL to navigate to. |
time | string | optional. Time to wait in milliseconds. |
Ask method
ask method helps you retrieve information from a page in a structured way using Zod schemas.
Parameters
Parameter | Type | Description |
---|---|---|
goal | string | required. A descriptive goal for the action to be performed. |
options | Object | optional. Additional options to customize the ask action. |
AskOptions
Property | Type | Description |
---|---|---|
currentPage | Page | optional (LOCAL mode only). The Playwright Page instance. |
schema | ZodSchema | optional. Zod schema to validate the extracted data against. |