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.

import { NfigClient } from 'nfig-sdk';

const nfig = new NfigClient({
  apiKey: "YOUR_API_KEY",
  browserMode: "REMOTE", 
  debug: true          
});

ParameterTypeDescription
apiKeystringrequired. Your API key from the Nfig Portal.
browserMode”LOCAL” | “REMOTE”optional. Specifies the browser mode. Defaults to REMOTE.
debugbooleanoptional. Enables debug logging if set to true.

Session Management

Note: A managed session in Nfig is active for 5 minutes in remote mode.

(async () => {
    const nfig = new NfigClient({
        browserMode: "REMOTE",
        debug: true
    });
    const { previewUrl } = await nfig.createSession()
    try {
        await nfig.act('Go to google.com')
    } catch (error) {
        await nfig.endSession()
    }
}())

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

(async () => {
  const nfig = new NfigClient({ apiKey: "YOUR_API_KEY", browserMode: "REMOTE", });
  const session = await nfig.createSession();
  console.log(session.previewUrl);
})();

Usage Example: LOCAL Mode

import { chromium } from 'playwright';

(async () => {
  const browser = await chromium.launch({ headless: false });
  const page = await browser.newPage();
  const nfig = new NfigClient({ apiKey: "YOUR_API_KEY", browserMode: "LOCAL", });
  const session = await nfig.createSession({ currentPage:page });
})();

Create Session Options

ParameterTypeDescription
currentPagePageoptional (LOCAL mode only). The Playwright Page instance to be used for the session.
proxybooleanoptional (REMOTE mode only). Enables proxy while creating session.
authOptionsAuthOptionsoptional (REMOTE mode only). Enabled authentication while creating a session.

Auth Options in CreateSession

The AuthOptions provides configuration for authentication-related settings when creating a session using the createSession method. It allows specifying the authentication app and other parameters for customizing authentication behavior.

The AuthOptions includes the following fields:

ParameterTypeDescription
authAppenumThe authentication app is to be used during the session. Must be one of the allowed auth apps.

Supported Authentications and Enums

The following table lists the standard integrations that are currently supported:

NameauthApp field enum🚧
Amazonamazon
Deltadelta
DoorDashdoordash
Facebookfacebook
Githubgithub
Instacartinstacart
Instagraminstagram
LinkedInlinkedin
Nextdoornextdoor🧪 experimental
OpenTableopentable
Twitter / Xtwitter
Resyresy
Uberuber
UberEatsuber_eats🧪 experimental
Unitedunited_airlines

Usage Example: REMOTE Mode with authentication and proxy

import { chromium } from 'playwright';
import NfigClient from 'nfig-sdk';

(async () => {
  const session = await nfig.createSession({
            proxy:true,
            authOptions:{
            authApp:'linkedin'
            }
        });
  console.log(session.previewUrl);
})();

Ending a Session

await nfig.endSession();

EndSessionResponse

FieldTypeDescription
successbooleanIndicates if the session was ended successfully.
messagestringInformational message about the session termination.

Note: Ending a session is a necessary action to avoid unexpected billing.

Exporting Session Video

await nfig.exportVideo(sessionToken: string);

ExportVideoResponse

FieldTypeDescription
successbooleanIndicates if the session was ended successfully.

Note: You will an email with the link to exported video.

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

await nfig.act("Go to airbnb");
await nfig.act("search the location as  himachal pradesh");
await nfig.act("select the location as  himachal pradesh");
await nfig.act('click on the check in date');
await nfig.act('choose the date as december 15 2024')
await nfig.act('click on the checkout')
await nfig.act('choose the checkout date as december 20 2024')
await nfig.act('click on the guests')
await nfig.act('Set number of adults as 2')
await nfig.act('click on the search button')

Usage example: REMOTE mode

await nfig.act("Go to airbnb");
await nfig.act("Set the location as Himachal Pradesh");
await nfig.act('Set check in date as December 15 2024')
await nfig.act('Set check out date as December 20 2024')
await nfig.act('Set number of adults as 2')
await nfig.act('click on the search button')

SDK Methods


Act method

act method performs specific actions on a webpage.


Basic usage

const response = await nfig.act("Go to google.com");

Fallback Method

In LOCAL mode, act supports fallback method to try an action manually and use agent as a fallback method.

const response = await nfig.act("Click on login button", { action: "click", selector: "#login-button" });

Parameters

ParameterTypeDescription
goalstringrequired. A descriptive goal for the action to be performed.
optionsObjectoptional. Additional options to customize the action.

Options

PropertyTypeDescription
currentPagePage(playwright)optional (LOCAL mode only). The Playwright Page instance.
executebooleanoptional. 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.
selectorstringoptional (For click and type action only). CSS selector of the element to type into.
iterCountnumberoptional (For click action only). Number of times to perform the click action.
inputTextstringoptional (for type action only). CSS selector of the element to type into.
enterbooleanoptional (for type action only). If set to true, simulates pressing the Enter key after typing.
urlstringoptional. URL to navigate to.
timestringoptional. Time to wait in milliseconds.

Ask method

ask method helps you retrieve information from a page in a structured way using Zod schemas.

const response = await nfig.ask("Extract the pricing informations", {
  schema: priceSchema,
  pageMode: "fullPage" 
});

Parameters

ParameterTypeDescription
goalstringrequired. A descriptive goal for the action to be performed.
optionsObjectoptional. Additional options to customize the ask action.

AskOptions

PropertyTypeDescription
currentPagePageoptional (LOCAL mode only). The Playwright Page instance.
schemaZodSchemaoptional. Zod schema to validate the extracted data against.
pageMode”fullPage”
or
“viewPort”
optional (LOCAL mode only).

Choose between scraping the entire page or just the visible viewport.