nstbrowser-sdk-node
Version:
nst browser node sdk
312 lines (308 loc) • 10.6 kB
TypeScript
interface NstResponse<T> {
data: T;
err: boolean;
msg: string;
code: number;
}
interface PageQueryResponse {
hasNextPage: boolean;
hasPrevPage: boolean;
limit: number;
nextPage: number;
offset: number;
page: number;
pagingCounter: number;
prevPage: number;
totalDocs: number;
totalPages: number;
}
type KernelType = 0 | 1;
type PlatForm = 0 | 1 | 2 | 3 | 4;
type KernelEnum = 'chromium';
type PlatformEnum = 'linux' | 'mac' | 'windows';
type BrowserStatus = 'starting' | 'running' | 'stopping';
type KernelInfo = {
name: string;
kernelType: KernelType;
kernelMilestone: string;
customVersion: string;
path: string;
size: number;
formatSize: string;
};
type RunningBrowserInfo = {
kernelType: KernelInfo;
name: string;
profileId: string;
remoteDebuggingPort: number;
running: boolean;
userDirPath: string;
version: string;
};
type NstBrowserOption = {
apiAddress?: string;
timeout: number;
};
interface BrowserProfileStatus {
kernel: KernelType;
kernelMilestone: string;
name: string;
platform: PlatForm;
profileId: string;
remoteDebuggingPort: number;
running: boolean;
starting: boolean;
stopping: boolean;
}
interface CreateProfileParam {
groupId?: string;
kernel: KernelEnum;
kernelMilestone: string;
name: string;
platform: PlatformEnum;
args?: Record<string, string>;
groupName?: string;
fingerprint?: Record<string, any>;
note?: string;
proxy?: string;
proxyGroupName?: string;
startupUrls?: string[];
}
interface ConnectBrowserParam {
autoClose?: boolean;
timedCloseSec?: number;
headless?: boolean;
incognito?: boolean;
skipProxyChecking?: boolean;
remoteDebuggingPort?: string;
args?: Record<string, string>;
proxy?: string;
startupUrls?: string[];
clearCacheOnClose: boolean;
}
interface StartOnceBrowserParam extends CreateProfileParam, ConnectBrowserParam {
fingerprintRandomness?: boolean;
}
interface BrowserPagesData {
description: string;
devtoolsFrontendUrl: string;
id: string;
title: string;
type: string;
url: string;
webSocketDebuggerUrl: string;
}
interface CreateProfileResponse {
_id: string;
createdAt: string;
fingerprintId: string;
groupId: string;
kernel: number;
kernelMilestone: string;
kernelVersion: string;
name: string;
note: string;
platform: number;
platformVersion: string;
profileId: string;
saveLocal: boolean;
status: number;
tags: string[];
teamId: string;
uaFullVersion: string;
updatedAt: string;
userId: string;
}
interface ProfileParams {
groupId?: string;
page?: string;
pageSize?: string;
s?: string;
tags?: string;
}
interface ProfileItem {
fingerprintId: string;
groupId: string;
kernel: number;
kernelMilestone: string;
kernelVersion: string;
name: string;
note: string;
platform: number;
platformVersion: string;
profileId: string;
proxyConfig: {
checker: string;
host: string;
password: string;
port: string;
protocol: string;
proxySetting: string;
proxyType: string;
url: string;
username: string;
};
tags: string[];
teamId: string;
uaFullVersion: string;
userId: string;
}
interface ProfileListResponse extends PageQueryResponse {
docs: ProfileItem[];
}
interface BatchUpdateProxyData {
profileIds?: string[];
proxyConfig: {
checker: string;
host: string;
password: string;
port: string;
protocol: string;
proxySetting: string;
proxyType: string;
url: string;
username: string;
};
}
interface BrowserRemoteDebuggerData {
port: number;
webSocketDebuggerUrl: string;
profileId: string;
}
interface LaunchBrowserParam {
config?: string;
}
interface TagsItem {
color: string;
name: string;
}
interface BatchUpdateProfilesTagParam {
profileIds: string[];
tags: TagsItem[];
}
interface BrowserManager {
forceStart: (profileId: string) => Promise<NstResponse<any>>;
start: (profileId: string) => Promise<NstResponse<any>>;
startSome: (profileIds: string[]) => Promise<NstResponse<any>>;
stop: (profileId: string) => Promise<NstResponse<any>>;
stopSome: (profileIds: string[]) => Promise<NstResponse<any>>;
stopAll: () => Promise<NstResponse<any>>;
/** @deprecated please use `getRunningBrowser` instead */
getRunningBrowserAll: () => Promise<NstResponse<RunningBrowserInfo[]>>;
getRunningBrowser: () => Promise<NstResponse<RunningBrowserInfo[]>>;
getRemoteDebuggingAddress: (profileId: string) => Promise<NstResponse<string>>;
getProfilesStatus: () => Promise<NstResponse<BrowserProfileStatus[]>>;
}
interface ProfileManager {
createProfile: (param: CreateProfileParam) => Promise<NstResponse<any>>;
deleteProfile: (profileId: string) => Promise<NstResponse<any>>;
profiles: (param: ProfileParams) => Promise<NstResponse<any>>;
batchUpdateProxy: (param: BatchUpdateProxyData) => Promise<NstResponse<any>>;
getProfileTags: () => Promise<NstResponse<any>>;
batchUpdateProfileTags: (param: BatchUpdateProfilesTagParam) => Promise<NstResponse<any>>;
batchCreateProfileTags: (param: BatchUpdateProfilesTagParam) => Promise<NstResponse<any>>;
batchClearProfileTags: (profileIds: string[]) => Promise<NstResponse<any>>;
clearCookies: (profileId: string) => Promise<NstResponse<any>>;
clearProfileCache: (profileId: string) => Promise<NstResponse<any>>;
batchClearProfileCache: (profileIds: string[]) => Promise<NstResponse<any>>;
}
interface DevtoolManager {
launchNewBrowser: (config: string) => Promise<NstResponse<any>>;
launchExistBrowser: (profileId: string, config?: LaunchBrowserParam) => Promise<NstResponse<any>>;
}
interface BrowserlessConfig {
platform?: 'windows' | 'mac' | 'linux';
kernel?: 'chromium';
kernelMilestone?: '128';
args?: Record<string, string>;
fingerprint?: Record<string, any>;
}
interface BrowserlessOptions {
apiKey: string;
proxy: string;
baseURL?: string;
}
interface LoadOptions extends BrowserlessConfig {
sessionId?: string;
}
interface MyScreenshotOptions extends BrowserlessConfig {
sessionId?: string;
fullPage?: boolean;
encoding?: 'base64' | 'binary';
type?: 'png' | 'jpeg' | 'webp';
}
declare class Browserless {
private apiKey;
private baseURL;
private proxy;
constructor(options: BrowserlessOptions);
load(url: string, options: LoadOptions): Promise<string>;
screenshot(url: string, options?: MyScreenshotOptions): Promise<Uint8Array>;
getConnectURL(sessionId?: string): string | undefined;
private getBrowser;
private getPage;
private loadPage;
private doScreenshot;
}
/** A more standardized `NstBrowserV2` is recommended. */
declare class NstBrowser {
static instance: null | NstBrowser;
protected apiKey: string;
protected timeout: number;
protected apiAddress: string;
constructor(key: string, options?: NstBrowserOption);
browserManager(): BrowserManager;
profileManager(): ProfileManager;
devtool(): DevtoolManager;
}
declare class NstBrowserV2 {
static instance: null | NstBrowserV2;
protected apiKey: string;
protected timeout: number;
protected apiAddress: string;
constructor(key: string, options?: NstBrowserOption);
browsers(): {
startBrowser: (profileId: string) => Promise<NstResponse<any>>;
startBrowsers: (profileIds: string[]) => Promise<NstResponse<any>>;
startOnceBrowser: (param: StartOnceBrowserParam) => Promise<NstResponse<any>>;
stopBrowser: (profileId: string) => Promise<NstResponse<any>>;
stopBrowsers: (profileIds: string[]) => Promise<NstResponse<any>>;
getBrowsers: (status?: BrowserStatus) => Promise<NstResponse<RunningBrowserInfo[]>>;
getBrowserPages: (profileId: string) => Promise<NstResponse<BrowserPagesData[]>>;
getBrowserDebugger: (profileId: string) => Promise<NstResponse<BrowserRemoteDebuggerData>>;
};
profiles(): {
updateProfileProxy: (profileId: string, param: BatchUpdateProxyData["proxyConfig"]) => Promise<NstResponse<any>>;
resetProfileProxy: (profileId: string) => Promise<NstResponse<any>>;
createProfileTags: (profileId: string, param: TagsItem[]) => Promise<NstResponse<any>>;
updateProfileTags: (profileId: string, param: TagsItem[]) => Promise<NstResponse<any>>;
clearProfileTags: (profileId: string) => Promise<NstResponse<any>>;
batchUpdateProxy: (param: BatchUpdateProxyData) => Promise<NstResponse<any>>;
batchResetProfileProxy: (profileIds: string[]) => Promise<NstResponse<any>>;
batchCreateProfileTags: (param: BatchUpdateProfilesTagParam) => Promise<NstResponse<any>>;
batchUpdateProfileTags: (param: BatchUpdateProfilesTagParam) => Promise<NstResponse<any>>;
batchClearProfileTags: (profileIds: string[]) => Promise<NstResponse<any>>;
createProfile: (param: CreateProfileParam) => Promise<NstResponse<CreateProfileResponse>>;
deleteProfile: (profileId: string) => Promise<NstResponse<any>>;
deleteProfiles: (profileIds: string[]) => Promise<NstResponse<any>>;
getProfiles: (param?: ProfileParams) => Promise<NstResponse<ProfileListResponse>>;
getProfileTags: () => Promise<NstResponse<any>>;
getAllProfileGroups: (groupName?: string) => Promise<NstResponse<any>>;
changeProfileGroup: (profileId: string, groupId: string) => Promise<NstResponse<any>>;
batchChangeProfileGroup: (param: {
profileIds: string[];
groupId: string;
}) => Promise<NstResponse<any>>;
};
cdpEndpoints(): {
connectBrowser: (profileId: string, param: ConnectBrowserParam) => Promise<NstResponse<BrowserRemoteDebuggerData>>;
connectOnceBrowser: (param: StartOnceBrowserParam) => Promise<NstResponse<BrowserRemoteDebuggerData>>;
};
locals(): {
clearProfileCache: (profileId: string) => Promise<NstResponse<any>>;
clearProfileCookies: (profileId: string) => Promise<NstResponse<any>>;
};
}
type NstBrowserTypes = typeof NstBrowser;
type NstBrowserV2Types = typeof NstBrowserV2;
export { Browserless, NstBrowser, type NstBrowserTypes, NstBrowserV2, type NstBrowserV2Types };