browser-pilot 0.0.1
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/LICENSE +21 -0
- package/README.md +539 -0
- package/dist/actions.cjs +277 -0
- package/dist/actions.d.cts +33 -0
- package/dist/actions.d.ts +33 -0
- package/dist/actions.mjs +8 -0
- package/dist/browser.cjs +2765 -0
- package/dist/browser.d.cts +71 -0
- package/dist/browser.d.ts +71 -0
- package/dist/browser.mjs +19 -0
- package/dist/cdp.cjs +279 -0
- package/dist/cdp.d.cts +230 -0
- package/dist/cdp.d.ts +230 -0
- package/dist/cdp.mjs +10 -0
- package/dist/chunk-BCOZUKWS.mjs +251 -0
- package/dist/chunk-FI55U7JS.mjs +2108 -0
- package/dist/chunk-R3PS4PCM.mjs +207 -0
- package/dist/chunk-YEHK2XY3.mjs +250 -0
- package/dist/chunk-ZIQA4JOT.mjs +226 -0
- package/dist/cli.cjs +3587 -0
- package/dist/cli.d.cts +23 -0
- package/dist/cli.d.ts +23 -0
- package/dist/cli.mjs +827 -0
- package/dist/client-7Nqka5MV.d.cts +53 -0
- package/dist/client-7Nqka5MV.d.ts +53 -0
- package/dist/index.cjs +3074 -0
- package/dist/index.d.cts +157 -0
- package/dist/index.d.ts +157 -0
- package/dist/index.mjs +64 -0
- package/dist/providers.cjs +238 -0
- package/dist/providers.d.cts +86 -0
- package/dist/providers.d.ts +86 -0
- package/dist/providers.mjs +16 -0
- package/dist/types-Cs89wle0.d.cts +925 -0
- package/dist/types-DL_-3BZk.d.ts +925 -0
- package/dist/types-D_uDqh0Z.d.cts +56 -0
- package/dist/types-D_uDqh0Z.d.ts +56 -0
- package/package.json +91 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export { BatchExecutor, addBatchToPage } from './actions.cjs';
|
|
2
|
+
import { R as RequestPattern, a as RequestHandler } from './types-Cs89wle0.cjs';
|
|
3
|
+
export { d as ActionOptions, e as ActionResult, A as ActionType, B as BatchOptions, b as BatchResult, Q as ClearCookiesOptions, C as ConsoleHandler, f as ConsoleMessage, g as ConsoleMessageType, z as ContinueRequestOptions, X as Cookie, h as CustomSelectConfig, Y as DeleteCookieOptions, w as DeviceDescriptor, x as DeviceName, D as Dialog, i as DialogHandler, j as DialogType, k as Download, E as ElementInfo, l as ElementNotFoundError, m as EmulationState, n as ErrorHandler, H as FailRequestOptions, F as FileInput, o as FillOptions, J as FulfillRequestOptions, G as GeolocationOptions, I as InteractiveElement, K as InterceptedRequest, N as NavigationError, p as NetworkIdleOptions, P as Page, q as PageError, r as PageSnapshot, L as RequestActions, M as ResourceType, O as RouteOptions, Z as SetCookieOptions, s as SnapshotNode, S as Step, c as StepResult, t as SubmitOptions, T as TimeoutError, u as TypeOptions, U as UserAgentMetadata, v as UserAgentOptions, V as ViewportOptions, W as WaitForOptions, _ as WaitOptions, $ as WaitResult, a0 as WaitState, y as devices, a1 as waitForAnyElement, a2 as waitForElement, a3 as waitForNavigation, a4 as waitForNetworkIdle } from './types-Cs89wle0.cjs';
|
|
4
|
+
export { Browser, BrowserOptions, connect } from './browser.cjs';
|
|
5
|
+
import { C as CDPClient } from './client-7Nqka5MV.cjs';
|
|
6
|
+
export { a as CDPClientOptions, c as createCDPClient } from './client-7Nqka5MV.cjs';
|
|
7
|
+
export { CDPError } from './cdp.cjs';
|
|
8
|
+
export { BrowserBaseProvider, BrowserlessProvider, GenericProvider, createProvider, discoverTargets, getBrowserWebSocketUrl } from './providers.cjs';
|
|
9
|
+
export { C as ConnectOptions, a as CreateSessionOptions, P as Provider, b as ProviderSession } from './types-D_uDqh0Z.cjs';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Request interception implementation
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
declare class RequestInterceptor {
|
|
16
|
+
private cdp;
|
|
17
|
+
private enabled;
|
|
18
|
+
private handlers;
|
|
19
|
+
private pendingRequests;
|
|
20
|
+
private boundHandleRequestPaused;
|
|
21
|
+
private boundHandleAuthRequired;
|
|
22
|
+
constructor(cdp: CDPClient);
|
|
23
|
+
/**
|
|
24
|
+
* Enable request interception with optional patterns
|
|
25
|
+
*/
|
|
26
|
+
enable(patterns?: RequestPattern[]): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Disable request interception
|
|
29
|
+
*/
|
|
30
|
+
disable(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Add a request handler
|
|
33
|
+
*/
|
|
34
|
+
addHandler(pattern: RequestPattern, handler: RequestHandler): () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Handle paused request from CDP
|
|
37
|
+
*/
|
|
38
|
+
private handleRequestPaused;
|
|
39
|
+
/**
|
|
40
|
+
* Handle auth challenge
|
|
41
|
+
*/
|
|
42
|
+
private handleAuthRequired;
|
|
43
|
+
/**
|
|
44
|
+
* Check if request matches pattern
|
|
45
|
+
*/
|
|
46
|
+
private matchesPattern;
|
|
47
|
+
/**
|
|
48
|
+
* Convert glob pattern to regex
|
|
49
|
+
*/
|
|
50
|
+
private globToRegex;
|
|
51
|
+
/**
|
|
52
|
+
* Create actions object for handler
|
|
53
|
+
*/
|
|
54
|
+
private createActions;
|
|
55
|
+
/**
|
|
56
|
+
* Continue a paused request
|
|
57
|
+
*/
|
|
58
|
+
private continueRequest;
|
|
59
|
+
/**
|
|
60
|
+
* Fulfill a request with custom response
|
|
61
|
+
*/
|
|
62
|
+
private fulfillRequest;
|
|
63
|
+
/**
|
|
64
|
+
* Fail/abort a request
|
|
65
|
+
*/
|
|
66
|
+
private failRequest;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Execution tracing and logging
|
|
71
|
+
*/
|
|
72
|
+
type TraceLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
73
|
+
type TraceCategory = 'cdp' | 'action' | 'wait' | 'navigation' | 'batch';
|
|
74
|
+
interface TraceEvent {
|
|
75
|
+
/** Event timestamp */
|
|
76
|
+
timestamp: string;
|
|
77
|
+
/** Log level */
|
|
78
|
+
level: TraceLevel;
|
|
79
|
+
/** Event category */
|
|
80
|
+
category: TraceCategory;
|
|
81
|
+
/** Action being performed */
|
|
82
|
+
action?: string;
|
|
83
|
+
/** Target selector(s) */
|
|
84
|
+
selector?: string | string[];
|
|
85
|
+
/** Selector that was actually used */
|
|
86
|
+
selectorUsed?: string;
|
|
87
|
+
/** Duration in ms */
|
|
88
|
+
durationMs?: number;
|
|
89
|
+
/** Whether action succeeded */
|
|
90
|
+
success?: boolean;
|
|
91
|
+
/** Error message if failed */
|
|
92
|
+
error?: string;
|
|
93
|
+
/** Selectors that failed before success */
|
|
94
|
+
failedSelectors?: Array<{
|
|
95
|
+
selector: string;
|
|
96
|
+
reason: string;
|
|
97
|
+
}>;
|
|
98
|
+
/** Current page URL */
|
|
99
|
+
url?: string;
|
|
100
|
+
/** Additional data */
|
|
101
|
+
data?: Record<string, unknown>;
|
|
102
|
+
}
|
|
103
|
+
type TraceOutput = 'console' | 'callback' | 'silent';
|
|
104
|
+
interface TracerOptions {
|
|
105
|
+
/** Whether tracing is enabled */
|
|
106
|
+
enabled: boolean;
|
|
107
|
+
/** Output destination */
|
|
108
|
+
output: TraceOutput;
|
|
109
|
+
/** Custom callback for trace events */
|
|
110
|
+
callback?: (event: TraceEvent) => void;
|
|
111
|
+
/** Minimum level to log */
|
|
112
|
+
level?: TraceLevel;
|
|
113
|
+
/** Include timing information */
|
|
114
|
+
includeTimings?: boolean;
|
|
115
|
+
}
|
|
116
|
+
declare class Tracer {
|
|
117
|
+
private options;
|
|
118
|
+
constructor(options?: Partial<TracerOptions>);
|
|
119
|
+
/**
|
|
120
|
+
* Emit a trace event
|
|
121
|
+
*/
|
|
122
|
+
emit(event: Omit<TraceEvent, 'timestamp'>): void;
|
|
123
|
+
/**
|
|
124
|
+
* Log event to console
|
|
125
|
+
*/
|
|
126
|
+
private logToConsole;
|
|
127
|
+
/**
|
|
128
|
+
* Create a child tracer with modified options
|
|
129
|
+
*/
|
|
130
|
+
child(options: Partial<TracerOptions>): Tracer;
|
|
131
|
+
/**
|
|
132
|
+
* Enable tracing
|
|
133
|
+
*/
|
|
134
|
+
enable(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Disable tracing
|
|
137
|
+
*/
|
|
138
|
+
disable(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Check if tracing is enabled
|
|
141
|
+
*/
|
|
142
|
+
get isEnabled(): boolean;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get the global tracer instance
|
|
146
|
+
*/
|
|
147
|
+
declare function getTracer(): Tracer;
|
|
148
|
+
/**
|
|
149
|
+
* Enable global tracing
|
|
150
|
+
*/
|
|
151
|
+
declare function enableTracing(options?: Partial<Omit<TracerOptions, 'enabled'>>): Tracer;
|
|
152
|
+
/**
|
|
153
|
+
* Disable global tracing
|
|
154
|
+
*/
|
|
155
|
+
declare function disableTracing(): void;
|
|
156
|
+
|
|
157
|
+
export { CDPClient, RequestHandler, RequestInterceptor, RequestPattern, type TraceCategory, type TraceEvent, type TraceLevel, Tracer, type TracerOptions, disableTracing, enableTracing, getTracer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export { BatchExecutor, addBatchToPage } from './actions.js';
|
|
2
|
+
import { R as RequestPattern, a as RequestHandler } from './types-DL_-3BZk.js';
|
|
3
|
+
export { d as ActionOptions, e as ActionResult, A as ActionType, B as BatchOptions, b as BatchResult, Q as ClearCookiesOptions, C as ConsoleHandler, f as ConsoleMessage, g as ConsoleMessageType, z as ContinueRequestOptions, X as Cookie, h as CustomSelectConfig, Y as DeleteCookieOptions, w as DeviceDescriptor, x as DeviceName, D as Dialog, i as DialogHandler, j as DialogType, k as Download, E as ElementInfo, l as ElementNotFoundError, m as EmulationState, n as ErrorHandler, H as FailRequestOptions, F as FileInput, o as FillOptions, J as FulfillRequestOptions, G as GeolocationOptions, I as InteractiveElement, K as InterceptedRequest, N as NavigationError, p as NetworkIdleOptions, P as Page, q as PageError, r as PageSnapshot, L as RequestActions, M as ResourceType, O as RouteOptions, Z as SetCookieOptions, s as SnapshotNode, S as Step, c as StepResult, t as SubmitOptions, T as TimeoutError, u as TypeOptions, U as UserAgentMetadata, v as UserAgentOptions, V as ViewportOptions, W as WaitForOptions, _ as WaitOptions, $ as WaitResult, a0 as WaitState, y as devices, a1 as waitForAnyElement, a2 as waitForElement, a3 as waitForNavigation, a4 as waitForNetworkIdle } from './types-DL_-3BZk.js';
|
|
4
|
+
export { Browser, BrowserOptions, connect } from './browser.js';
|
|
5
|
+
import { C as CDPClient } from './client-7Nqka5MV.js';
|
|
6
|
+
export { a as CDPClientOptions, c as createCDPClient } from './client-7Nqka5MV.js';
|
|
7
|
+
export { CDPError } from './cdp.js';
|
|
8
|
+
export { BrowserBaseProvider, BrowserlessProvider, GenericProvider, createProvider, discoverTargets, getBrowserWebSocketUrl } from './providers.js';
|
|
9
|
+
export { C as ConnectOptions, a as CreateSessionOptions, P as Provider, b as ProviderSession } from './types-D_uDqh0Z.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Request interception implementation
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
declare class RequestInterceptor {
|
|
16
|
+
private cdp;
|
|
17
|
+
private enabled;
|
|
18
|
+
private handlers;
|
|
19
|
+
private pendingRequests;
|
|
20
|
+
private boundHandleRequestPaused;
|
|
21
|
+
private boundHandleAuthRequired;
|
|
22
|
+
constructor(cdp: CDPClient);
|
|
23
|
+
/**
|
|
24
|
+
* Enable request interception with optional patterns
|
|
25
|
+
*/
|
|
26
|
+
enable(patterns?: RequestPattern[]): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Disable request interception
|
|
29
|
+
*/
|
|
30
|
+
disable(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Add a request handler
|
|
33
|
+
*/
|
|
34
|
+
addHandler(pattern: RequestPattern, handler: RequestHandler): () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Handle paused request from CDP
|
|
37
|
+
*/
|
|
38
|
+
private handleRequestPaused;
|
|
39
|
+
/**
|
|
40
|
+
* Handle auth challenge
|
|
41
|
+
*/
|
|
42
|
+
private handleAuthRequired;
|
|
43
|
+
/**
|
|
44
|
+
* Check if request matches pattern
|
|
45
|
+
*/
|
|
46
|
+
private matchesPattern;
|
|
47
|
+
/**
|
|
48
|
+
* Convert glob pattern to regex
|
|
49
|
+
*/
|
|
50
|
+
private globToRegex;
|
|
51
|
+
/**
|
|
52
|
+
* Create actions object for handler
|
|
53
|
+
*/
|
|
54
|
+
private createActions;
|
|
55
|
+
/**
|
|
56
|
+
* Continue a paused request
|
|
57
|
+
*/
|
|
58
|
+
private continueRequest;
|
|
59
|
+
/**
|
|
60
|
+
* Fulfill a request with custom response
|
|
61
|
+
*/
|
|
62
|
+
private fulfillRequest;
|
|
63
|
+
/**
|
|
64
|
+
* Fail/abort a request
|
|
65
|
+
*/
|
|
66
|
+
private failRequest;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Execution tracing and logging
|
|
71
|
+
*/
|
|
72
|
+
type TraceLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
73
|
+
type TraceCategory = 'cdp' | 'action' | 'wait' | 'navigation' | 'batch';
|
|
74
|
+
interface TraceEvent {
|
|
75
|
+
/** Event timestamp */
|
|
76
|
+
timestamp: string;
|
|
77
|
+
/** Log level */
|
|
78
|
+
level: TraceLevel;
|
|
79
|
+
/** Event category */
|
|
80
|
+
category: TraceCategory;
|
|
81
|
+
/** Action being performed */
|
|
82
|
+
action?: string;
|
|
83
|
+
/** Target selector(s) */
|
|
84
|
+
selector?: string | string[];
|
|
85
|
+
/** Selector that was actually used */
|
|
86
|
+
selectorUsed?: string;
|
|
87
|
+
/** Duration in ms */
|
|
88
|
+
durationMs?: number;
|
|
89
|
+
/** Whether action succeeded */
|
|
90
|
+
success?: boolean;
|
|
91
|
+
/** Error message if failed */
|
|
92
|
+
error?: string;
|
|
93
|
+
/** Selectors that failed before success */
|
|
94
|
+
failedSelectors?: Array<{
|
|
95
|
+
selector: string;
|
|
96
|
+
reason: string;
|
|
97
|
+
}>;
|
|
98
|
+
/** Current page URL */
|
|
99
|
+
url?: string;
|
|
100
|
+
/** Additional data */
|
|
101
|
+
data?: Record<string, unknown>;
|
|
102
|
+
}
|
|
103
|
+
type TraceOutput = 'console' | 'callback' | 'silent';
|
|
104
|
+
interface TracerOptions {
|
|
105
|
+
/** Whether tracing is enabled */
|
|
106
|
+
enabled: boolean;
|
|
107
|
+
/** Output destination */
|
|
108
|
+
output: TraceOutput;
|
|
109
|
+
/** Custom callback for trace events */
|
|
110
|
+
callback?: (event: TraceEvent) => void;
|
|
111
|
+
/** Minimum level to log */
|
|
112
|
+
level?: TraceLevel;
|
|
113
|
+
/** Include timing information */
|
|
114
|
+
includeTimings?: boolean;
|
|
115
|
+
}
|
|
116
|
+
declare class Tracer {
|
|
117
|
+
private options;
|
|
118
|
+
constructor(options?: Partial<TracerOptions>);
|
|
119
|
+
/**
|
|
120
|
+
* Emit a trace event
|
|
121
|
+
*/
|
|
122
|
+
emit(event: Omit<TraceEvent, 'timestamp'>): void;
|
|
123
|
+
/**
|
|
124
|
+
* Log event to console
|
|
125
|
+
*/
|
|
126
|
+
private logToConsole;
|
|
127
|
+
/**
|
|
128
|
+
* Create a child tracer with modified options
|
|
129
|
+
*/
|
|
130
|
+
child(options: Partial<TracerOptions>): Tracer;
|
|
131
|
+
/**
|
|
132
|
+
* Enable tracing
|
|
133
|
+
*/
|
|
134
|
+
enable(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Disable tracing
|
|
137
|
+
*/
|
|
138
|
+
disable(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Check if tracing is enabled
|
|
141
|
+
*/
|
|
142
|
+
get isEnabled(): boolean;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get the global tracer instance
|
|
146
|
+
*/
|
|
147
|
+
declare function getTracer(): Tracer;
|
|
148
|
+
/**
|
|
149
|
+
* Enable global tracing
|
|
150
|
+
*/
|
|
151
|
+
declare function enableTracing(options?: Partial<Omit<TracerOptions, 'enabled'>>): Tracer;
|
|
152
|
+
/**
|
|
153
|
+
* Disable global tracing
|
|
154
|
+
*/
|
|
155
|
+
declare function disableTracing(): void;
|
|
156
|
+
|
|
157
|
+
export { CDPClient, RequestHandler, RequestInterceptor, RequestPattern, type TraceCategory, type TraceEvent, type TraceLevel, Tracer, type TracerOptions, disableTracing, enableTracing, getTracer };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Tracer,
|
|
3
|
+
devices,
|
|
4
|
+
disableTracing,
|
|
5
|
+
enableTracing,
|
|
6
|
+
getTracer
|
|
7
|
+
} from "./chunk-ZIQA4JOT.mjs";
|
|
8
|
+
import {
|
|
9
|
+
Browser,
|
|
10
|
+
ElementNotFoundError,
|
|
11
|
+
NavigationError,
|
|
12
|
+
Page,
|
|
13
|
+
RequestInterceptor,
|
|
14
|
+
TimeoutError,
|
|
15
|
+
connect,
|
|
16
|
+
waitForAnyElement,
|
|
17
|
+
waitForElement,
|
|
18
|
+
waitForNavigation,
|
|
19
|
+
waitForNetworkIdle
|
|
20
|
+
} from "./chunk-FI55U7JS.mjs";
|
|
21
|
+
import {
|
|
22
|
+
CDPError,
|
|
23
|
+
createCDPClient
|
|
24
|
+
} from "./chunk-BCOZUKWS.mjs";
|
|
25
|
+
import {
|
|
26
|
+
BrowserBaseProvider,
|
|
27
|
+
BrowserlessProvider,
|
|
28
|
+
GenericProvider,
|
|
29
|
+
createProvider,
|
|
30
|
+
discoverTargets,
|
|
31
|
+
getBrowserWebSocketUrl
|
|
32
|
+
} from "./chunk-R3PS4PCM.mjs";
|
|
33
|
+
import {
|
|
34
|
+
BatchExecutor,
|
|
35
|
+
addBatchToPage
|
|
36
|
+
} from "./chunk-YEHK2XY3.mjs";
|
|
37
|
+
export {
|
|
38
|
+
BatchExecutor,
|
|
39
|
+
Browser,
|
|
40
|
+
BrowserBaseProvider,
|
|
41
|
+
BrowserlessProvider,
|
|
42
|
+
CDPError,
|
|
43
|
+
ElementNotFoundError,
|
|
44
|
+
GenericProvider,
|
|
45
|
+
NavigationError,
|
|
46
|
+
Page,
|
|
47
|
+
RequestInterceptor,
|
|
48
|
+
TimeoutError,
|
|
49
|
+
Tracer,
|
|
50
|
+
addBatchToPage,
|
|
51
|
+
connect,
|
|
52
|
+
createCDPClient,
|
|
53
|
+
createProvider,
|
|
54
|
+
devices,
|
|
55
|
+
disableTracing,
|
|
56
|
+
discoverTargets,
|
|
57
|
+
enableTracing,
|
|
58
|
+
getBrowserWebSocketUrl,
|
|
59
|
+
getTracer,
|
|
60
|
+
waitForAnyElement,
|
|
61
|
+
waitForElement,
|
|
62
|
+
waitForNavigation,
|
|
63
|
+
waitForNetworkIdle
|
|
64
|
+
};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/providers/index.ts
|
|
21
|
+
var providers_exports = {};
|
|
22
|
+
__export(providers_exports, {
|
|
23
|
+
BrowserBaseProvider: () => BrowserBaseProvider,
|
|
24
|
+
BrowserlessProvider: () => BrowserlessProvider,
|
|
25
|
+
GenericProvider: () => GenericProvider,
|
|
26
|
+
createProvider: () => createProvider,
|
|
27
|
+
discoverTargets: () => discoverTargets,
|
|
28
|
+
getBrowserWebSocketUrl: () => getBrowserWebSocketUrl
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(providers_exports);
|
|
31
|
+
|
|
32
|
+
// src/providers/browserbase.ts
|
|
33
|
+
var BrowserBaseProvider = class {
|
|
34
|
+
name = "browserbase";
|
|
35
|
+
apiKey;
|
|
36
|
+
projectId;
|
|
37
|
+
baseUrl;
|
|
38
|
+
constructor(options) {
|
|
39
|
+
this.apiKey = options.apiKey;
|
|
40
|
+
this.projectId = options.projectId;
|
|
41
|
+
this.baseUrl = options.baseUrl ?? "https://api.browserbase.com";
|
|
42
|
+
}
|
|
43
|
+
async createSession(options = {}) {
|
|
44
|
+
const response = await fetch(`${this.baseUrl}/v1/sessions`, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: {
|
|
47
|
+
"X-BB-API-Key": this.apiKey,
|
|
48
|
+
"Content-Type": "application/json"
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
projectId: this.projectId,
|
|
52
|
+
browserSettings: {
|
|
53
|
+
viewport: options.width && options.height ? {
|
|
54
|
+
width: options.width,
|
|
55
|
+
height: options.height
|
|
56
|
+
} : void 0
|
|
57
|
+
},
|
|
58
|
+
...options
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
const text = await response.text();
|
|
63
|
+
throw new Error(`BrowserBase createSession failed: ${response.status} ${text}`);
|
|
64
|
+
}
|
|
65
|
+
const session = await response.json();
|
|
66
|
+
const connectResponse = await fetch(`${this.baseUrl}/v1/sessions/${session.id}`, {
|
|
67
|
+
headers: {
|
|
68
|
+
"X-BB-API-Key": this.apiKey
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
if (!connectResponse.ok) {
|
|
72
|
+
throw new Error(`BrowserBase getSession failed: ${connectResponse.status}`);
|
|
73
|
+
}
|
|
74
|
+
const sessionDetails = await connectResponse.json();
|
|
75
|
+
if (!sessionDetails.connectUrl) {
|
|
76
|
+
throw new Error("BrowserBase session does not have a connectUrl");
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
wsUrl: sessionDetails.connectUrl,
|
|
80
|
+
sessionId: session.id,
|
|
81
|
+
metadata: {
|
|
82
|
+
debugUrl: sessionDetails.debugUrl,
|
|
83
|
+
projectId: this.projectId,
|
|
84
|
+
status: sessionDetails.status
|
|
85
|
+
},
|
|
86
|
+
close: async () => {
|
|
87
|
+
await fetch(`${this.baseUrl}/v1/sessions/${session.id}`, {
|
|
88
|
+
method: "DELETE",
|
|
89
|
+
headers: {
|
|
90
|
+
"X-BB-API-Key": this.apiKey
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async resumeSession(sessionId) {
|
|
97
|
+
const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}`, {
|
|
98
|
+
headers: {
|
|
99
|
+
"X-BB-API-Key": this.apiKey
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
if (!response.ok) {
|
|
103
|
+
throw new Error(`BrowserBase resumeSession failed: ${response.status}`);
|
|
104
|
+
}
|
|
105
|
+
const session = await response.json();
|
|
106
|
+
if (!session.connectUrl) {
|
|
107
|
+
throw new Error("BrowserBase session does not have a connectUrl (may be closed)");
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
wsUrl: session.connectUrl,
|
|
111
|
+
sessionId: session.id,
|
|
112
|
+
metadata: {
|
|
113
|
+
debugUrl: session.debugUrl,
|
|
114
|
+
projectId: this.projectId,
|
|
115
|
+
status: session.status
|
|
116
|
+
},
|
|
117
|
+
close: async () => {
|
|
118
|
+
await fetch(`${this.baseUrl}/v1/sessions/${sessionId}`, {
|
|
119
|
+
method: "DELETE",
|
|
120
|
+
headers: {
|
|
121
|
+
"X-BB-API-Key": this.apiKey
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// src/providers/browserless.ts
|
|
130
|
+
var BrowserlessProvider = class {
|
|
131
|
+
name = "browserless";
|
|
132
|
+
token;
|
|
133
|
+
baseUrl;
|
|
134
|
+
constructor(options) {
|
|
135
|
+
this.token = options.token;
|
|
136
|
+
this.baseUrl = options.baseUrl ?? "wss://chrome.browserless.io";
|
|
137
|
+
}
|
|
138
|
+
async createSession(options = {}) {
|
|
139
|
+
const params = new URLSearchParams({
|
|
140
|
+
token: this.token
|
|
141
|
+
});
|
|
142
|
+
if (options.width && options.height) {
|
|
143
|
+
params.set("--window-size", `${options.width},${options.height}`);
|
|
144
|
+
}
|
|
145
|
+
if (options.proxy?.server) {
|
|
146
|
+
params.set("--proxy-server", options.proxy.server);
|
|
147
|
+
}
|
|
148
|
+
const wsUrl = `${this.baseUrl}?${params.toString()}`;
|
|
149
|
+
return {
|
|
150
|
+
wsUrl,
|
|
151
|
+
metadata: {
|
|
152
|
+
provider: "browserless"
|
|
153
|
+
},
|
|
154
|
+
close: async () => {
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// Browserless doesn't support session resumption in the same way
|
|
159
|
+
// Each connection is a fresh browser instance
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/providers/generic.ts
|
|
163
|
+
var GenericProvider = class {
|
|
164
|
+
name = "generic";
|
|
165
|
+
wsUrl;
|
|
166
|
+
constructor(options) {
|
|
167
|
+
this.wsUrl = options.wsUrl;
|
|
168
|
+
}
|
|
169
|
+
async createSession(_options = {}) {
|
|
170
|
+
return {
|
|
171
|
+
wsUrl: this.wsUrl,
|
|
172
|
+
metadata: {
|
|
173
|
+
provider: "generic"
|
|
174
|
+
},
|
|
175
|
+
close: async () => {
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
async function discoverTargets(host = "localhost:9222") {
|
|
181
|
+
const protocol = host.includes("://") ? "" : "http://";
|
|
182
|
+
const response = await fetch(`${protocol}${host}/json/list`);
|
|
183
|
+
if (!response.ok) {
|
|
184
|
+
throw new Error(`Failed to discover targets: ${response.status}`);
|
|
185
|
+
}
|
|
186
|
+
return await response.json();
|
|
187
|
+
}
|
|
188
|
+
async function getBrowserWebSocketUrl(host = "localhost:9222") {
|
|
189
|
+
const protocol = host.includes("://") ? "" : "http://";
|
|
190
|
+
const response = await fetch(`${protocol}${host}/json/version`);
|
|
191
|
+
if (!response.ok) {
|
|
192
|
+
throw new Error(`Failed to get browser info: ${response.status}`);
|
|
193
|
+
}
|
|
194
|
+
const info = await response.json();
|
|
195
|
+
return info.webSocketDebuggerUrl;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/providers/index.ts
|
|
199
|
+
function createProvider(options) {
|
|
200
|
+
switch (options.provider) {
|
|
201
|
+
case "browserbase":
|
|
202
|
+
if (!options.apiKey) {
|
|
203
|
+
throw new Error("BrowserBase provider requires apiKey");
|
|
204
|
+
}
|
|
205
|
+
if (!options.projectId) {
|
|
206
|
+
throw new Error("BrowserBase provider requires projectId");
|
|
207
|
+
}
|
|
208
|
+
return new BrowserBaseProvider({
|
|
209
|
+
apiKey: options.apiKey,
|
|
210
|
+
projectId: options.projectId
|
|
211
|
+
});
|
|
212
|
+
case "browserless":
|
|
213
|
+
if (!options.apiKey) {
|
|
214
|
+
throw new Error("Browserless provider requires apiKey (token)");
|
|
215
|
+
}
|
|
216
|
+
return new BrowserlessProvider({
|
|
217
|
+
token: options.apiKey
|
|
218
|
+
});
|
|
219
|
+
case "generic":
|
|
220
|
+
if (!options.wsUrl) {
|
|
221
|
+
throw new Error("Generic provider requires wsUrl");
|
|
222
|
+
}
|
|
223
|
+
return new GenericProvider({
|
|
224
|
+
wsUrl: options.wsUrl
|
|
225
|
+
});
|
|
226
|
+
default:
|
|
227
|
+
throw new Error(`Unknown provider: ${options.provider}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
231
|
+
0 && (module.exports = {
|
|
232
|
+
BrowserBaseProvider,
|
|
233
|
+
BrowserlessProvider,
|
|
234
|
+
GenericProvider,
|
|
235
|
+
createProvider,
|
|
236
|
+
discoverTargets,
|
|
237
|
+
getBrowserWebSocketUrl
|
|
238
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { P as Provider, a as CreateSessionOptions, b as ProviderSession, C as ConnectOptions } from './types-D_uDqh0Z.cjs';
|
|
2
|
+
export { c as ProxyConfig } from './types-D_uDqh0Z.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* BrowserBase provider implementation
|
|
6
|
+
* https://docs.browserbase.com/
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
interface BrowserBaseOptions {
|
|
10
|
+
apiKey: string;
|
|
11
|
+
projectId: string;
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
declare class BrowserBaseProvider implements Provider {
|
|
15
|
+
readonly name = "browserbase";
|
|
16
|
+
private readonly apiKey;
|
|
17
|
+
private readonly projectId;
|
|
18
|
+
private readonly baseUrl;
|
|
19
|
+
constructor(options: BrowserBaseOptions);
|
|
20
|
+
createSession(options?: CreateSessionOptions): Promise<ProviderSession>;
|
|
21
|
+
resumeSession(sessionId: string): Promise<ProviderSession>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Browserless.io provider implementation
|
|
26
|
+
* https://www.browserless.io/docs/
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
interface BrowserlessOptions {
|
|
30
|
+
token: string;
|
|
31
|
+
baseUrl?: string;
|
|
32
|
+
}
|
|
33
|
+
declare class BrowserlessProvider implements Provider {
|
|
34
|
+
readonly name = "browserless";
|
|
35
|
+
private readonly token;
|
|
36
|
+
private readonly baseUrl;
|
|
37
|
+
constructor(options: BrowserlessOptions);
|
|
38
|
+
createSession(options?: CreateSessionOptions): Promise<ProviderSession>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Generic CDP provider for direct WebSocket connections
|
|
43
|
+
* Use this when connecting to a local Chrome instance or any CDP-compatible endpoint
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
interface GenericProviderOptions {
|
|
47
|
+
/** WebSocket URL to connect to (e.g., ws://localhost:9222/devtools/browser/xxx) */
|
|
48
|
+
wsUrl: string;
|
|
49
|
+
}
|
|
50
|
+
declare class GenericProvider implements Provider {
|
|
51
|
+
readonly name = "generic";
|
|
52
|
+
private readonly wsUrl;
|
|
53
|
+
constructor(options: GenericProviderOptions);
|
|
54
|
+
createSession(_options?: CreateSessionOptions): Promise<ProviderSession>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Discover CDP endpoints from a Chrome DevTools JSON endpoint
|
|
58
|
+
* Useful for connecting to a local Chrome instance
|
|
59
|
+
*
|
|
60
|
+
* @param host - Host to query (e.g., "localhost:9222")
|
|
61
|
+
* @returns List of available debug targets
|
|
62
|
+
*/
|
|
63
|
+
declare function discoverTargets(host?: string): Promise<Array<{
|
|
64
|
+
id: string;
|
|
65
|
+
type: string;
|
|
66
|
+
url: string;
|
|
67
|
+
webSocketDebuggerUrl?: string;
|
|
68
|
+
}>>;
|
|
69
|
+
/**
|
|
70
|
+
* Get the browser-level WebSocket debugger URL
|
|
71
|
+
*
|
|
72
|
+
* @param host - Host to query (e.g., "localhost:9222")
|
|
73
|
+
* @returns WebSocket URL for browser-level CDP connection
|
|
74
|
+
*/
|
|
75
|
+
declare function getBrowserWebSocketUrl(host?: string): Promise<string>;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Provider module exports
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Create a provider instance based on connection options
|
|
83
|
+
*/
|
|
84
|
+
declare function createProvider(options: ConnectOptions): Provider;
|
|
85
|
+
|
|
86
|
+
export { type BrowserBaseOptions, BrowserBaseProvider, type BrowserlessOptions, BrowserlessProvider, ConnectOptions, CreateSessionOptions, GenericProvider, type GenericProviderOptions, Provider, ProviderSession, createProvider, discoverTargets, getBrowserWebSocketUrl };
|