browser-pilot 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -667
- package/dist/actions.cjs +1073 -41
- package/dist/actions.d.cts +11 -3
- package/dist/actions.d.ts +11 -3
- package/dist/actions.mjs +1 -1
- package/dist/browser-ZCR6AA4D.mjs +11 -0
- package/dist/browser.cjs +1431 -62
- package/dist/browser.d.cts +4 -4
- package/dist/browser.d.ts +4 -4
- package/dist/browser.mjs +4 -4
- package/dist/cdp.cjs +5 -1
- package/dist/cdp.d.cts +1 -1
- package/dist/cdp.d.ts +1 -1
- package/dist/cdp.mjs +1 -1
- package/dist/{chunk-7NDR6V7S.mjs → chunk-6GBYX7C2.mjs} +1405 -528
- package/dist/{chunk-KIFB526Y.mjs → chunk-BVZALQT4.mjs} +5 -1
- package/dist/chunk-DTVRFXKI.mjs +35 -0
- package/dist/chunk-EZNZ72VA.mjs +563 -0
- package/dist/{chunk-SPSZZH22.mjs → chunk-LCNFBXB5.mjs} +9 -33
- package/dist/{chunk-IN5HPAPB.mjs → chunk-NNEHWWHL.mjs} +28 -10
- package/dist/chunk-TJ5B56NV.mjs +804 -0
- package/dist/{chunk-XMJABKCF.mjs → chunk-V3VLBQAM.mjs} +1073 -41
- package/dist/cli.mjs +2799 -1176
- package/dist/{client-Ck2nQksT.d.cts → client-B5QBRgIy.d.cts} +2 -0
- package/dist/{client-Ck2nQksT.d.ts → client-B5QBRgIy.d.ts} +2 -0
- package/dist/{client-3AFV2IAF.mjs → client-JWWZWO6L.mjs} +4 -2
- package/dist/index.cjs +1441 -52
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +19 -7
- package/dist/page-IUUTJ3SW.mjs +7 -0
- package/dist/providers.cjs +637 -2
- package/dist/providers.d.cts +2 -2
- package/dist/providers.d.ts +2 -2
- package/dist/providers.mjs +17 -3
- package/dist/{types-CjT0vClo.d.ts → types-BflRmiDz.d.cts} +17 -3
- package/dist/{types-BSoh5v1Y.d.cts → types-BzM-IfsL.d.ts} +17 -3
- package/dist/types-DeVSWhXj.d.cts +142 -0
- package/dist/types-DeVSWhXj.d.ts +142 -0
- package/package.json +1 -1
- package/dist/browser-LZTEHUDI.mjs +0 -9
- package/dist/chunk-BRAFQUMG.mjs +0 -229
- package/dist/types--wXNHUwt.d.cts +0 -56
- package/dist/types--wXNHUwt.d.ts +0 -56
package/dist/providers.mjs
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BrowserBaseProvider,
|
|
3
|
+
BrowserEndpointResolutionError,
|
|
3
4
|
BrowserlessProvider,
|
|
4
5
|
GenericProvider,
|
|
6
|
+
buildLocalBrowserScanTargets,
|
|
5
7
|
createProvider,
|
|
8
|
+
discoverLocalBrowsers,
|
|
6
9
|
discoverTargets,
|
|
7
|
-
getBrowserWebSocketUrl
|
|
8
|
-
|
|
10
|
+
getBrowserWebSocketUrl,
|
|
11
|
+
parseDevToolsActivePortFile,
|
|
12
|
+
resolveBrowserEndpoint,
|
|
13
|
+
resolveChromeUserDataDirs
|
|
14
|
+
} from "./chunk-EZNZ72VA.mjs";
|
|
15
|
+
import "./chunk-BVZALQT4.mjs";
|
|
16
|
+
import "./chunk-JXAUPHZM.mjs";
|
|
9
17
|
export {
|
|
10
18
|
BrowserBaseProvider,
|
|
19
|
+
BrowserEndpointResolutionError,
|
|
11
20
|
BrowserlessProvider,
|
|
12
21
|
GenericProvider,
|
|
22
|
+
buildLocalBrowserScanTargets,
|
|
13
23
|
createProvider,
|
|
24
|
+
discoverLocalBrowsers,
|
|
14
25
|
discoverTargets,
|
|
15
|
-
getBrowserWebSocketUrl
|
|
26
|
+
getBrowserWebSocketUrl,
|
|
27
|
+
parseDevToolsActivePortFile,
|
|
28
|
+
resolveBrowserEndpoint,
|
|
29
|
+
resolveChromeUserDataDirs
|
|
16
30
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CDPClient } from './client-
|
|
1
|
+
import { C as CDPClient } from './client-B5QBRgIy.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Audio I/O type definitions
|
|
@@ -1247,7 +1247,7 @@ declare class Page {
|
|
|
1247
1247
|
*/
|
|
1248
1248
|
|
|
1249
1249
|
type FailureReason = 'missing' | 'hidden' | 'covered' | 'disabled' | 'readonly' | 'detached' | 'replaced' | 'notEditable' | 'timeout' | 'navigation' | 'cdpError' | 'unknown';
|
|
1250
|
-
type ActionType = 'goto' | 'click' | 'fill' | 'type' | 'select' | 'check' | 'uncheck' | 'submit' | 'press' | 'shortcut' | 'focus' | 'hover' | 'scroll' | 'wait' | 'snapshot' | 'forms' | 'screenshot' | 'evaluate' | 'text' | 'newTab' | 'closeTab' | 'switchFrame' | 'switchToMain' | 'assertVisible' | 'assertExists' | 'assertText' | 'assertUrl' | 'assertValue';
|
|
1250
|
+
type ActionType = 'goto' | 'click' | 'fill' | 'type' | 'select' | 'check' | 'uncheck' | 'submit' | 'press' | 'shortcut' | 'focus' | 'hover' | 'scroll' | 'wait' | 'snapshot' | 'forms' | 'screenshot' | 'evaluate' | 'text' | 'newTab' | 'closeTab' | 'switchFrame' | 'switchToMain' | 'assertVisible' | 'assertExists' | 'assertText' | 'assertUrl' | 'assertValue' | 'waitForWsMessage' | 'assertNoConsoleErrors' | 'assertTextChanged' | 'assertPermission' | 'assertMediaTrackLive';
|
|
1251
1251
|
interface Step {
|
|
1252
1252
|
/** Action type */
|
|
1253
1253
|
action: ActionType;
|
|
@@ -1284,7 +1284,9 @@ interface Step {
|
|
|
1284
1284
|
/** Custom select: option selector */
|
|
1285
1285
|
option?: string | string[];
|
|
1286
1286
|
/** Custom select: match type */
|
|
1287
|
-
match?:
|
|
1287
|
+
match?: string;
|
|
1288
|
+
/** Structured matcher for trace-backed waits */
|
|
1289
|
+
where?: Record<string, unknown>;
|
|
1288
1290
|
/** Scroll coordinates */
|
|
1289
1291
|
x?: number;
|
|
1290
1292
|
y?: number;
|
|
@@ -1302,6 +1304,18 @@ interface Step {
|
|
|
1302
1304
|
retry?: number;
|
|
1303
1305
|
/** Delay between retries in ms (default: 500) */
|
|
1304
1306
|
retryDelay?: number;
|
|
1307
|
+
/** Previous text expected before a change */
|
|
1308
|
+
from?: string;
|
|
1309
|
+
/** Text expected after a change */
|
|
1310
|
+
to?: string;
|
|
1311
|
+
/** Permission or resource name */
|
|
1312
|
+
name?: string;
|
|
1313
|
+
/** Expected permission state */
|
|
1314
|
+
state?: string;
|
|
1315
|
+
/** Media track kind */
|
|
1316
|
+
kind?: 'audio' | 'video';
|
|
1317
|
+
/** Assertion observation window in milliseconds */
|
|
1318
|
+
windowMs?: number;
|
|
1305
1319
|
}
|
|
1306
1320
|
interface RecordOptions {
|
|
1307
1321
|
/** Base directory for screenshots and recording.json. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CDPClient } from './client-
|
|
1
|
+
import { C as CDPClient } from './client-B5QBRgIy.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Audio I/O type definitions
|
|
@@ -1247,7 +1247,7 @@ declare class Page {
|
|
|
1247
1247
|
*/
|
|
1248
1248
|
|
|
1249
1249
|
type FailureReason = 'missing' | 'hidden' | 'covered' | 'disabled' | 'readonly' | 'detached' | 'replaced' | 'notEditable' | 'timeout' | 'navigation' | 'cdpError' | 'unknown';
|
|
1250
|
-
type ActionType = 'goto' | 'click' | 'fill' | 'type' | 'select' | 'check' | 'uncheck' | 'submit' | 'press' | 'shortcut' | 'focus' | 'hover' | 'scroll' | 'wait' | 'snapshot' | 'forms' | 'screenshot' | 'evaluate' | 'text' | 'newTab' | 'closeTab' | 'switchFrame' | 'switchToMain' | 'assertVisible' | 'assertExists' | 'assertText' | 'assertUrl' | 'assertValue';
|
|
1250
|
+
type ActionType = 'goto' | 'click' | 'fill' | 'type' | 'select' | 'check' | 'uncheck' | 'submit' | 'press' | 'shortcut' | 'focus' | 'hover' | 'scroll' | 'wait' | 'snapshot' | 'forms' | 'screenshot' | 'evaluate' | 'text' | 'newTab' | 'closeTab' | 'switchFrame' | 'switchToMain' | 'assertVisible' | 'assertExists' | 'assertText' | 'assertUrl' | 'assertValue' | 'waitForWsMessage' | 'assertNoConsoleErrors' | 'assertTextChanged' | 'assertPermission' | 'assertMediaTrackLive';
|
|
1251
1251
|
interface Step {
|
|
1252
1252
|
/** Action type */
|
|
1253
1253
|
action: ActionType;
|
|
@@ -1284,7 +1284,9 @@ interface Step {
|
|
|
1284
1284
|
/** Custom select: option selector */
|
|
1285
1285
|
option?: string | string[];
|
|
1286
1286
|
/** Custom select: match type */
|
|
1287
|
-
match?:
|
|
1287
|
+
match?: string;
|
|
1288
|
+
/** Structured matcher for trace-backed waits */
|
|
1289
|
+
where?: Record<string, unknown>;
|
|
1288
1290
|
/** Scroll coordinates */
|
|
1289
1291
|
x?: number;
|
|
1290
1292
|
y?: number;
|
|
@@ -1302,6 +1304,18 @@ interface Step {
|
|
|
1302
1304
|
retry?: number;
|
|
1303
1305
|
/** Delay between retries in ms (default: 500) */
|
|
1304
1306
|
retryDelay?: number;
|
|
1307
|
+
/** Previous text expected before a change */
|
|
1308
|
+
from?: string;
|
|
1309
|
+
/** Text expected after a change */
|
|
1310
|
+
to?: string;
|
|
1311
|
+
/** Permission or resource name */
|
|
1312
|
+
name?: string;
|
|
1313
|
+
/** Expected permission state */
|
|
1314
|
+
state?: string;
|
|
1315
|
+
/** Media track kind */
|
|
1316
|
+
kind?: 'audio' | 'video';
|
|
1317
|
+
/** Assertion observation window in milliseconds */
|
|
1318
|
+
windowMs?: number;
|
|
1305
1319
|
}
|
|
1306
1320
|
interface RecordOptions {
|
|
1307
1321
|
/** Base directory for screenshots and recording.json. */
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
type ChromeChannel = 'stable' | 'beta' | 'dev' | 'canary';
|
|
2
|
+
type ResolvedBrowserSource = 'explicit-ws' | 'devtools-active-port' | 'json-version';
|
|
3
|
+
interface LocalBrowserScanTarget {
|
|
4
|
+
channel: ChromeChannel | 'custom';
|
|
5
|
+
userDataDir: string;
|
|
6
|
+
portFile: string;
|
|
7
|
+
}
|
|
8
|
+
interface LocalBrowserCandidate extends LocalBrowserScanTarget {
|
|
9
|
+
port: number;
|
|
10
|
+
browserPath: string;
|
|
11
|
+
wsUrl: string;
|
|
12
|
+
browserVersion?: string;
|
|
13
|
+
}
|
|
14
|
+
type LocalDiscoveryFailureReason = 'missing-file' | 'unreadable-file' | 'malformed-file' | 'invalid-port' | 'invalid-path' | 'connection-refused' | 'connection-timeout' | 'unexpected-close' | 'connection-error' | 'cdp-error';
|
|
15
|
+
interface LocalDiscoveryFailure extends LocalBrowserScanTarget {
|
|
16
|
+
reason: LocalDiscoveryFailureReason;
|
|
17
|
+
message: string;
|
|
18
|
+
wsUrl?: string;
|
|
19
|
+
}
|
|
20
|
+
interface LocalBrowserDiscoveryResult {
|
|
21
|
+
candidates: LocalBrowserCandidate[];
|
|
22
|
+
failures: LocalDiscoveryFailure[];
|
|
23
|
+
}
|
|
24
|
+
interface ResolvedBrowserEndpoint {
|
|
25
|
+
wsUrl: string;
|
|
26
|
+
source: ResolvedBrowserSource;
|
|
27
|
+
channel?: ChromeChannel | 'custom';
|
|
28
|
+
userDataDir?: string;
|
|
29
|
+
}
|
|
30
|
+
interface ChromeUserDataDirOptions {
|
|
31
|
+
platform?: string;
|
|
32
|
+
env?: Record<string, string | undefined>;
|
|
33
|
+
homeDir?: string;
|
|
34
|
+
}
|
|
35
|
+
interface DiscoverLocalBrowsersOptions extends ChromeUserDataDirOptions {
|
|
36
|
+
channel?: ChromeChannel;
|
|
37
|
+
userDataDir?: string;
|
|
38
|
+
probeTimeoutMs?: number;
|
|
39
|
+
}
|
|
40
|
+
interface ResolveBrowserEndpointOptions extends DiscoverLocalBrowsersOptions {
|
|
41
|
+
explicitWsUrl?: string;
|
|
42
|
+
allowLocalDiscovery?: boolean;
|
|
43
|
+
allowLegacyHostFallback?: boolean;
|
|
44
|
+
legacyHost?: string;
|
|
45
|
+
}
|
|
46
|
+
interface ProbeResult {
|
|
47
|
+
browserVersion?: string;
|
|
48
|
+
}
|
|
49
|
+
interface LocalDiscoveryDependencies {
|
|
50
|
+
readTextFile(path: string): Promise<string>;
|
|
51
|
+
probeBrowserWebSocket(wsUrl: string, timeoutMs: number): Promise<ProbeResult>;
|
|
52
|
+
getLegacyBrowserWebSocketUrl(host: string): Promise<string>;
|
|
53
|
+
}
|
|
54
|
+
interface ParsedDevToolsActivePort {
|
|
55
|
+
port: number;
|
|
56
|
+
browserPath: string;
|
|
57
|
+
wsUrl: string;
|
|
58
|
+
}
|
|
59
|
+
declare function resolveChromeUserDataDirs(options?: ChromeUserDataDirOptions): Record<ChromeChannel, string>;
|
|
60
|
+
declare function buildLocalBrowserScanTargets(options?: DiscoverLocalBrowsersOptions): LocalBrowserScanTarget[];
|
|
61
|
+
declare function parseDevToolsActivePortFile(content: string): ParsedDevToolsActivePort;
|
|
62
|
+
declare function discoverLocalBrowsers(options?: DiscoverLocalBrowsersOptions, deps?: LocalDiscoveryDependencies): Promise<LocalBrowserDiscoveryResult>;
|
|
63
|
+
type BrowserEndpointResolutionErrorCode = 'multiple-local-browsers' | 'browser-not-found';
|
|
64
|
+
declare class BrowserEndpointResolutionError extends Error {
|
|
65
|
+
readonly code: BrowserEndpointResolutionErrorCode;
|
|
66
|
+
readonly details: {
|
|
67
|
+
candidates?: LocalBrowserCandidate[];
|
|
68
|
+
failures?: LocalDiscoveryFailure[];
|
|
69
|
+
legacyError?: Error;
|
|
70
|
+
legacyHost?: string;
|
|
71
|
+
};
|
|
72
|
+
readonly name = "BrowserEndpointResolutionError";
|
|
73
|
+
constructor(code: BrowserEndpointResolutionErrorCode, message: string, details?: {
|
|
74
|
+
candidates?: LocalBrowserCandidate[];
|
|
75
|
+
failures?: LocalDiscoveryFailure[];
|
|
76
|
+
legacyError?: Error;
|
|
77
|
+
legacyHost?: string;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
declare function resolveBrowserEndpoint(options?: ResolveBrowserEndpointOptions, deps?: LocalDiscoveryDependencies): Promise<ResolvedBrowserEndpoint>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Provider type definitions
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
interface ProviderSession {
|
|
87
|
+
/** WebSocket URL to connect to CDP */
|
|
88
|
+
wsUrl: string;
|
|
89
|
+
/** Provider-specific session ID (for resumption) */
|
|
90
|
+
sessionId?: string;
|
|
91
|
+
/** Additional metadata from the provider */
|
|
92
|
+
metadata?: Record<string, unknown>;
|
|
93
|
+
/** Close the provider session */
|
|
94
|
+
close(): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
interface Provider {
|
|
97
|
+
/** Provider name identifier */
|
|
98
|
+
readonly name: string;
|
|
99
|
+
/** Create a new browser session */
|
|
100
|
+
createSession(options?: CreateSessionOptions): Promise<ProviderSession>;
|
|
101
|
+
/** Resume an existing session by ID */
|
|
102
|
+
resumeSession?(sessionId: string): Promise<ProviderSession>;
|
|
103
|
+
}
|
|
104
|
+
interface CreateSessionOptions {
|
|
105
|
+
/** Viewport width */
|
|
106
|
+
width?: number;
|
|
107
|
+
/** Viewport height */
|
|
108
|
+
height?: number;
|
|
109
|
+
/** Enable recording (if provider supports) */
|
|
110
|
+
recording?: boolean;
|
|
111
|
+
/** Proxy configuration */
|
|
112
|
+
proxy?: ProxyConfig;
|
|
113
|
+
/** Additional provider-specific options */
|
|
114
|
+
[key: string]: unknown;
|
|
115
|
+
}
|
|
116
|
+
interface ProxyConfig {
|
|
117
|
+
server: string;
|
|
118
|
+
username?: string;
|
|
119
|
+
password?: string;
|
|
120
|
+
}
|
|
121
|
+
interface ConnectOptions {
|
|
122
|
+
/** Provider type */
|
|
123
|
+
provider: 'browserbase' | 'browserless' | 'generic';
|
|
124
|
+
/** API key for hosted providers */
|
|
125
|
+
apiKey?: string;
|
|
126
|
+
/** Project ID (for BrowserBase) */
|
|
127
|
+
projectId?: string;
|
|
128
|
+
/** Direct WebSocket URL (for generic provider) */
|
|
129
|
+
wsUrl?: string;
|
|
130
|
+
/** Preferred local Chrome channel for auto-discovery (generic provider) */
|
|
131
|
+
channel?: ChromeChannel;
|
|
132
|
+
/** Explicit local Chrome user data dir for auto-discovery (generic provider) */
|
|
133
|
+
userDataDir?: string;
|
|
134
|
+
/** Session creation options */
|
|
135
|
+
session?: CreateSessionOptions;
|
|
136
|
+
/** Enable debug logging */
|
|
137
|
+
debug?: boolean;
|
|
138
|
+
/** Connection timeout in ms */
|
|
139
|
+
timeout?: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { BrowserEndpointResolutionError as B, type CreateSessionOptions as C, type DiscoverLocalBrowsersOptions as D, type Provider as P, type ResolvedBrowserEndpoint as R, type ProviderSession as a, type ConnectOptions as b, buildLocalBrowserScanTargets as c, type ChromeChannel as d, type ChromeUserDataDirOptions as e, discoverLocalBrowsers as f, type ResolvedBrowserSource as g, resolveChromeUserDataDirs as h, type ProxyConfig as i, parseDevToolsActivePortFile as p, resolveBrowserEndpoint as r };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
type ChromeChannel = 'stable' | 'beta' | 'dev' | 'canary';
|
|
2
|
+
type ResolvedBrowserSource = 'explicit-ws' | 'devtools-active-port' | 'json-version';
|
|
3
|
+
interface LocalBrowserScanTarget {
|
|
4
|
+
channel: ChromeChannel | 'custom';
|
|
5
|
+
userDataDir: string;
|
|
6
|
+
portFile: string;
|
|
7
|
+
}
|
|
8
|
+
interface LocalBrowserCandidate extends LocalBrowserScanTarget {
|
|
9
|
+
port: number;
|
|
10
|
+
browserPath: string;
|
|
11
|
+
wsUrl: string;
|
|
12
|
+
browserVersion?: string;
|
|
13
|
+
}
|
|
14
|
+
type LocalDiscoveryFailureReason = 'missing-file' | 'unreadable-file' | 'malformed-file' | 'invalid-port' | 'invalid-path' | 'connection-refused' | 'connection-timeout' | 'unexpected-close' | 'connection-error' | 'cdp-error';
|
|
15
|
+
interface LocalDiscoveryFailure extends LocalBrowserScanTarget {
|
|
16
|
+
reason: LocalDiscoveryFailureReason;
|
|
17
|
+
message: string;
|
|
18
|
+
wsUrl?: string;
|
|
19
|
+
}
|
|
20
|
+
interface LocalBrowserDiscoveryResult {
|
|
21
|
+
candidates: LocalBrowserCandidate[];
|
|
22
|
+
failures: LocalDiscoveryFailure[];
|
|
23
|
+
}
|
|
24
|
+
interface ResolvedBrowserEndpoint {
|
|
25
|
+
wsUrl: string;
|
|
26
|
+
source: ResolvedBrowserSource;
|
|
27
|
+
channel?: ChromeChannel | 'custom';
|
|
28
|
+
userDataDir?: string;
|
|
29
|
+
}
|
|
30
|
+
interface ChromeUserDataDirOptions {
|
|
31
|
+
platform?: string;
|
|
32
|
+
env?: Record<string, string | undefined>;
|
|
33
|
+
homeDir?: string;
|
|
34
|
+
}
|
|
35
|
+
interface DiscoverLocalBrowsersOptions extends ChromeUserDataDirOptions {
|
|
36
|
+
channel?: ChromeChannel;
|
|
37
|
+
userDataDir?: string;
|
|
38
|
+
probeTimeoutMs?: number;
|
|
39
|
+
}
|
|
40
|
+
interface ResolveBrowserEndpointOptions extends DiscoverLocalBrowsersOptions {
|
|
41
|
+
explicitWsUrl?: string;
|
|
42
|
+
allowLocalDiscovery?: boolean;
|
|
43
|
+
allowLegacyHostFallback?: boolean;
|
|
44
|
+
legacyHost?: string;
|
|
45
|
+
}
|
|
46
|
+
interface ProbeResult {
|
|
47
|
+
browserVersion?: string;
|
|
48
|
+
}
|
|
49
|
+
interface LocalDiscoveryDependencies {
|
|
50
|
+
readTextFile(path: string): Promise<string>;
|
|
51
|
+
probeBrowserWebSocket(wsUrl: string, timeoutMs: number): Promise<ProbeResult>;
|
|
52
|
+
getLegacyBrowserWebSocketUrl(host: string): Promise<string>;
|
|
53
|
+
}
|
|
54
|
+
interface ParsedDevToolsActivePort {
|
|
55
|
+
port: number;
|
|
56
|
+
browserPath: string;
|
|
57
|
+
wsUrl: string;
|
|
58
|
+
}
|
|
59
|
+
declare function resolveChromeUserDataDirs(options?: ChromeUserDataDirOptions): Record<ChromeChannel, string>;
|
|
60
|
+
declare function buildLocalBrowserScanTargets(options?: DiscoverLocalBrowsersOptions): LocalBrowserScanTarget[];
|
|
61
|
+
declare function parseDevToolsActivePortFile(content: string): ParsedDevToolsActivePort;
|
|
62
|
+
declare function discoverLocalBrowsers(options?: DiscoverLocalBrowsersOptions, deps?: LocalDiscoveryDependencies): Promise<LocalBrowserDiscoveryResult>;
|
|
63
|
+
type BrowserEndpointResolutionErrorCode = 'multiple-local-browsers' | 'browser-not-found';
|
|
64
|
+
declare class BrowserEndpointResolutionError extends Error {
|
|
65
|
+
readonly code: BrowserEndpointResolutionErrorCode;
|
|
66
|
+
readonly details: {
|
|
67
|
+
candidates?: LocalBrowserCandidate[];
|
|
68
|
+
failures?: LocalDiscoveryFailure[];
|
|
69
|
+
legacyError?: Error;
|
|
70
|
+
legacyHost?: string;
|
|
71
|
+
};
|
|
72
|
+
readonly name = "BrowserEndpointResolutionError";
|
|
73
|
+
constructor(code: BrowserEndpointResolutionErrorCode, message: string, details?: {
|
|
74
|
+
candidates?: LocalBrowserCandidate[];
|
|
75
|
+
failures?: LocalDiscoveryFailure[];
|
|
76
|
+
legacyError?: Error;
|
|
77
|
+
legacyHost?: string;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
declare function resolveBrowserEndpoint(options?: ResolveBrowserEndpointOptions, deps?: LocalDiscoveryDependencies): Promise<ResolvedBrowserEndpoint>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Provider type definitions
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
interface ProviderSession {
|
|
87
|
+
/** WebSocket URL to connect to CDP */
|
|
88
|
+
wsUrl: string;
|
|
89
|
+
/** Provider-specific session ID (for resumption) */
|
|
90
|
+
sessionId?: string;
|
|
91
|
+
/** Additional metadata from the provider */
|
|
92
|
+
metadata?: Record<string, unknown>;
|
|
93
|
+
/** Close the provider session */
|
|
94
|
+
close(): Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
interface Provider {
|
|
97
|
+
/** Provider name identifier */
|
|
98
|
+
readonly name: string;
|
|
99
|
+
/** Create a new browser session */
|
|
100
|
+
createSession(options?: CreateSessionOptions): Promise<ProviderSession>;
|
|
101
|
+
/** Resume an existing session by ID */
|
|
102
|
+
resumeSession?(sessionId: string): Promise<ProviderSession>;
|
|
103
|
+
}
|
|
104
|
+
interface CreateSessionOptions {
|
|
105
|
+
/** Viewport width */
|
|
106
|
+
width?: number;
|
|
107
|
+
/** Viewport height */
|
|
108
|
+
height?: number;
|
|
109
|
+
/** Enable recording (if provider supports) */
|
|
110
|
+
recording?: boolean;
|
|
111
|
+
/** Proxy configuration */
|
|
112
|
+
proxy?: ProxyConfig;
|
|
113
|
+
/** Additional provider-specific options */
|
|
114
|
+
[key: string]: unknown;
|
|
115
|
+
}
|
|
116
|
+
interface ProxyConfig {
|
|
117
|
+
server: string;
|
|
118
|
+
username?: string;
|
|
119
|
+
password?: string;
|
|
120
|
+
}
|
|
121
|
+
interface ConnectOptions {
|
|
122
|
+
/** Provider type */
|
|
123
|
+
provider: 'browserbase' | 'browserless' | 'generic';
|
|
124
|
+
/** API key for hosted providers */
|
|
125
|
+
apiKey?: string;
|
|
126
|
+
/** Project ID (for BrowserBase) */
|
|
127
|
+
projectId?: string;
|
|
128
|
+
/** Direct WebSocket URL (for generic provider) */
|
|
129
|
+
wsUrl?: string;
|
|
130
|
+
/** Preferred local Chrome channel for auto-discovery (generic provider) */
|
|
131
|
+
channel?: ChromeChannel;
|
|
132
|
+
/** Explicit local Chrome user data dir for auto-discovery (generic provider) */
|
|
133
|
+
userDataDir?: string;
|
|
134
|
+
/** Session creation options */
|
|
135
|
+
session?: CreateSessionOptions;
|
|
136
|
+
/** Enable debug logging */
|
|
137
|
+
debug?: boolean;
|
|
138
|
+
/** Connection timeout in ms */
|
|
139
|
+
timeout?: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { BrowserEndpointResolutionError as B, type CreateSessionOptions as C, type DiscoverLocalBrowsersOptions as D, type Provider as P, type ResolvedBrowserEndpoint as R, type ProviderSession as a, type ConnectOptions as b, buildLocalBrowserScanTargets as c, type ChromeChannel as d, type ChromeUserDataDirOptions as e, discoverLocalBrowsers as f, type ResolvedBrowserSource as g, resolveChromeUserDataDirs as h, type ProxyConfig as i, parseDevToolsActivePortFile as p, resolveBrowserEndpoint as r };
|
package/package.json
CHANGED
package/dist/chunk-BRAFQUMG.mjs
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
// src/providers/browserbase.ts
|
|
2
|
-
var BrowserBaseProvider = class {
|
|
3
|
-
name = "browserbase";
|
|
4
|
-
apiKey;
|
|
5
|
-
projectId;
|
|
6
|
-
baseUrl;
|
|
7
|
-
constructor(options) {
|
|
8
|
-
this.apiKey = options.apiKey;
|
|
9
|
-
this.projectId = options.projectId;
|
|
10
|
-
this.baseUrl = options.baseUrl ?? "https://api.browserbase.com";
|
|
11
|
-
}
|
|
12
|
-
async createSession(options = {}) {
|
|
13
|
-
const response = await fetch(`${this.baseUrl}/v1/sessions`, {
|
|
14
|
-
method: "POST",
|
|
15
|
-
headers: {
|
|
16
|
-
"X-BB-API-Key": this.apiKey,
|
|
17
|
-
"Content-Type": "application/json"
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify({
|
|
20
|
-
projectId: this.projectId,
|
|
21
|
-
browserSettings: {
|
|
22
|
-
viewport: options.width && options.height ? {
|
|
23
|
-
width: options.width,
|
|
24
|
-
height: options.height
|
|
25
|
-
} : void 0
|
|
26
|
-
},
|
|
27
|
-
...options
|
|
28
|
-
})
|
|
29
|
-
});
|
|
30
|
-
if (!response.ok) {
|
|
31
|
-
const text = await response.text();
|
|
32
|
-
throw new Error(`BrowserBase createSession failed: ${response.status} ${text}`);
|
|
33
|
-
}
|
|
34
|
-
const session = await response.json();
|
|
35
|
-
const connectResponse = await fetch(`${this.baseUrl}/v1/sessions/${session.id}`, {
|
|
36
|
-
headers: {
|
|
37
|
-
"X-BB-API-Key": this.apiKey
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
if (!connectResponse.ok) {
|
|
41
|
-
throw new Error(`BrowserBase getSession failed: ${connectResponse.status}`);
|
|
42
|
-
}
|
|
43
|
-
const sessionDetails = await connectResponse.json();
|
|
44
|
-
if (!sessionDetails.connectUrl) {
|
|
45
|
-
throw new Error("BrowserBase session does not have a connectUrl");
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
wsUrl: sessionDetails.connectUrl,
|
|
49
|
-
sessionId: session.id,
|
|
50
|
-
metadata: {
|
|
51
|
-
debugUrl: sessionDetails.debugUrl,
|
|
52
|
-
projectId: this.projectId,
|
|
53
|
-
status: sessionDetails.status
|
|
54
|
-
},
|
|
55
|
-
close: async () => {
|
|
56
|
-
await fetch(`${this.baseUrl}/v1/sessions/${session.id}`, {
|
|
57
|
-
method: "DELETE",
|
|
58
|
-
headers: {
|
|
59
|
-
"X-BB-API-Key": this.apiKey
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
async resumeSession(sessionId) {
|
|
66
|
-
const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}`, {
|
|
67
|
-
headers: {
|
|
68
|
-
"X-BB-API-Key": this.apiKey
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
if (!response.ok) {
|
|
72
|
-
throw new Error(`BrowserBase resumeSession failed: ${response.status}`);
|
|
73
|
-
}
|
|
74
|
-
const session = await response.json();
|
|
75
|
-
if (!session.connectUrl) {
|
|
76
|
-
throw new Error("BrowserBase session does not have a connectUrl (may be closed)");
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
wsUrl: session.connectUrl,
|
|
80
|
-
sessionId: session.id,
|
|
81
|
-
metadata: {
|
|
82
|
-
debugUrl: session.debugUrl,
|
|
83
|
-
projectId: this.projectId,
|
|
84
|
-
status: session.status
|
|
85
|
-
},
|
|
86
|
-
close: async () => {
|
|
87
|
-
await fetch(`${this.baseUrl}/v1/sessions/${sessionId}`, {
|
|
88
|
-
method: "DELETE",
|
|
89
|
-
headers: {
|
|
90
|
-
"X-BB-API-Key": this.apiKey
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// src/providers/browserless.ts
|
|
99
|
-
var BrowserlessProvider = class {
|
|
100
|
-
name = "browserless";
|
|
101
|
-
token;
|
|
102
|
-
baseUrl;
|
|
103
|
-
constructor(options) {
|
|
104
|
-
this.token = options.token;
|
|
105
|
-
this.baseUrl = options.baseUrl ?? "wss://chrome.browserless.io";
|
|
106
|
-
}
|
|
107
|
-
async createSession(options = {}) {
|
|
108
|
-
const params = new URLSearchParams({
|
|
109
|
-
token: this.token
|
|
110
|
-
});
|
|
111
|
-
if (options.width && options.height) {
|
|
112
|
-
params.set("--window-size", `${options.width},${options.height}`);
|
|
113
|
-
}
|
|
114
|
-
if (options.proxy?.server) {
|
|
115
|
-
params.set("--proxy-server", options.proxy.server);
|
|
116
|
-
}
|
|
117
|
-
const wsUrl = `${this.baseUrl}?${params.toString()}`;
|
|
118
|
-
return {
|
|
119
|
-
wsUrl,
|
|
120
|
-
metadata: {
|
|
121
|
-
provider: "browserless"
|
|
122
|
-
},
|
|
123
|
-
close: async () => {
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
// Browserless doesn't support session resumption in the same way
|
|
128
|
-
// Each connection is a fresh browser instance
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// src/providers/generic.ts
|
|
132
|
-
function sleep(ms) {
|
|
133
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
134
|
-
}
|
|
135
|
-
async function fetchDevToolsJson(host, path, errorPrefix, options = {}) {
|
|
136
|
-
const protocol = host.includes("://") ? "" : "http://";
|
|
137
|
-
const attempts = options.attempts ?? 1;
|
|
138
|
-
let delayMs = options.initialDelayMs ?? 50;
|
|
139
|
-
const maxDelayMs = options.maxDelayMs ?? 250;
|
|
140
|
-
let lastError;
|
|
141
|
-
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
142
|
-
try {
|
|
143
|
-
const response = await fetch(`${protocol}${host}${path}`);
|
|
144
|
-
if (response.ok) {
|
|
145
|
-
return await response.json();
|
|
146
|
-
}
|
|
147
|
-
lastError = new Error(`${errorPrefix}: ${response.status}`);
|
|
148
|
-
} catch (error) {
|
|
149
|
-
lastError = new Error(
|
|
150
|
-
`${errorPrefix}: ${error instanceof Error ? error.message : String(error)}`
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
if (attempt < attempts) {
|
|
154
|
-
await sleep(delayMs);
|
|
155
|
-
delayMs = Math.min(delayMs * 2, maxDelayMs);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
throw lastError ?? new Error(errorPrefix);
|
|
159
|
-
}
|
|
160
|
-
var GenericProvider = class {
|
|
161
|
-
name = "generic";
|
|
162
|
-
wsUrl;
|
|
163
|
-
constructor(options) {
|
|
164
|
-
this.wsUrl = options.wsUrl;
|
|
165
|
-
}
|
|
166
|
-
async createSession(_options = {}) {
|
|
167
|
-
return {
|
|
168
|
-
wsUrl: this.wsUrl,
|
|
169
|
-
metadata: {
|
|
170
|
-
provider: "generic"
|
|
171
|
-
},
|
|
172
|
-
close: async () => {
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
async function discoverTargets(host = "localhost:9222") {
|
|
178
|
-
return fetchDevToolsJson(host, "/json/list", "Failed to discover targets");
|
|
179
|
-
}
|
|
180
|
-
async function getBrowserWebSocketUrl(host = "localhost:9222") {
|
|
181
|
-
const info = await fetchDevToolsJson(host, "/json/version", "Failed to get browser info", {
|
|
182
|
-
attempts: 10,
|
|
183
|
-
initialDelayMs: 50,
|
|
184
|
-
maxDelayMs: 250
|
|
185
|
-
});
|
|
186
|
-
return info.webSocketDebuggerUrl;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// src/providers/index.ts
|
|
190
|
-
function createProvider(options) {
|
|
191
|
-
switch (options.provider) {
|
|
192
|
-
case "browserbase":
|
|
193
|
-
if (!options.apiKey) {
|
|
194
|
-
throw new Error("BrowserBase provider requires apiKey");
|
|
195
|
-
}
|
|
196
|
-
if (!options.projectId) {
|
|
197
|
-
throw new Error("BrowserBase provider requires projectId");
|
|
198
|
-
}
|
|
199
|
-
return new BrowserBaseProvider({
|
|
200
|
-
apiKey: options.apiKey,
|
|
201
|
-
projectId: options.projectId
|
|
202
|
-
});
|
|
203
|
-
case "browserless":
|
|
204
|
-
if (!options.apiKey) {
|
|
205
|
-
throw new Error("Browserless provider requires apiKey (token)");
|
|
206
|
-
}
|
|
207
|
-
return new BrowserlessProvider({
|
|
208
|
-
token: options.apiKey
|
|
209
|
-
});
|
|
210
|
-
case "generic":
|
|
211
|
-
if (!options.wsUrl) {
|
|
212
|
-
throw new Error("Generic provider requires wsUrl");
|
|
213
|
-
}
|
|
214
|
-
return new GenericProvider({
|
|
215
|
-
wsUrl: options.wsUrl
|
|
216
|
-
});
|
|
217
|
-
default:
|
|
218
|
-
throw new Error(`Unknown provider: ${options.provider}`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export {
|
|
223
|
-
BrowserBaseProvider,
|
|
224
|
-
BrowserlessProvider,
|
|
225
|
-
GenericProvider,
|
|
226
|
-
discoverTargets,
|
|
227
|
-
getBrowserWebSocketUrl,
|
|
228
|
-
createProvider
|
|
229
|
-
};
|