@browserbasehq/sdk 1.1.4 → 1.1.6
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/dist/index.d.ts +9 -13
- package/dist/index.js +6 -16
- package/package.json +1 -1
- package/src/index.ts +13 -36
- package/test/lib.test.ts +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import BrowserbaseAISDK from './integrations/ai-sdk.js';
|
|
2
3
|
export type ClientOptions = {
|
|
3
4
|
apiKey?: string;
|
|
4
5
|
projectId?: string;
|
|
@@ -37,7 +38,7 @@ export type Session = {
|
|
|
37
38
|
id: string;
|
|
38
39
|
createdAt: string;
|
|
39
40
|
startedAt: string;
|
|
40
|
-
endedAt
|
|
41
|
+
endedAt?: string;
|
|
41
42
|
projectId: string;
|
|
42
43
|
status?: 'NEW' | 'CREATED' | 'ERROR' | 'RUNNING' | 'REQUEST_RELEASE' | 'RELEASING' | 'COMPLETED';
|
|
43
44
|
taskId?: string;
|
|
@@ -48,15 +49,16 @@ export type Session = {
|
|
|
48
49
|
details?: string;
|
|
49
50
|
logs?: string;
|
|
50
51
|
};
|
|
51
|
-
export type UpdateSessionOptions = {
|
|
52
|
-
projectId?: string;
|
|
53
|
-
status: Session['status'];
|
|
54
|
-
};
|
|
55
52
|
export type SessionRecording = {
|
|
56
53
|
type?: string;
|
|
57
54
|
time?: string;
|
|
58
55
|
data?: object;
|
|
59
56
|
};
|
|
57
|
+
export type DebugConnectionURLs = {
|
|
58
|
+
debuggerFullscreenUrl?: string;
|
|
59
|
+
debuggerUrl?: string;
|
|
60
|
+
wsUrl?: string;
|
|
61
|
+
};
|
|
60
62
|
export type SessionLog = {
|
|
61
63
|
sessionId?: string;
|
|
62
64
|
id: string;
|
|
@@ -74,22 +76,16 @@ export type SessionLog = {
|
|
|
74
76
|
};
|
|
75
77
|
pageId?: string;
|
|
76
78
|
};
|
|
77
|
-
export type DebugConnectionURLs = {
|
|
78
|
-
debuggerFullscreenUrl?: string;
|
|
79
|
-
debuggerUrl?: string;
|
|
80
|
-
wsUrl?: string;
|
|
81
|
-
};
|
|
82
79
|
export default class Browserbase {
|
|
83
80
|
private apiKey;
|
|
84
81
|
private projectId;
|
|
85
82
|
private baseAPIURL;
|
|
86
83
|
private baseConnectURL;
|
|
87
84
|
constructor(options?: ClientOptions);
|
|
88
|
-
|
|
85
|
+
getConnectURL({ sessionId, proxy }?: ConnectOptions): string;
|
|
89
86
|
listSessions(): Promise<Session[]>;
|
|
90
87
|
createSession(options?: CreateSessionOptions): Promise<Session>;
|
|
91
88
|
getSession(sessionId: string): Promise<Session>;
|
|
92
|
-
updateSession(sessionId: string, options: UpdateSessionOptions): Promise<Session>;
|
|
93
89
|
getSessionRecording(sessionId: string): Promise<SessionRecording[]>;
|
|
94
90
|
getSessionDownloads(sessionId: string, retryInterval?: number, retryCount?: number): Promise<Buffer>;
|
|
95
91
|
getDebugConnectionURLs(sessionId: string): Promise<DebugConnectionURLs>;
|
|
@@ -99,4 +95,4 @@ export default class Browserbase {
|
|
|
99
95
|
loadURLs(urls: string[], options?: LoadOptions): AsyncGenerator<string>;
|
|
100
96
|
screenshot(url: string, options?: ScreenshotOptions): Promise<Buffer>;
|
|
101
97
|
}
|
|
102
|
-
export { Browserbase };
|
|
98
|
+
export { Browserbase, BrowserbaseAISDK };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chromium } from 'playwright';
|
|
2
|
+
import BrowserbaseAISDK from './integrations/ai-sdk.js';
|
|
2
3
|
export default class Browserbase {
|
|
3
4
|
apiKey;
|
|
4
5
|
projectId;
|
|
@@ -11,7 +12,7 @@ export default class Browserbase {
|
|
|
11
12
|
this.baseConnectURL =
|
|
12
13
|
options.baseConnectURL || 'wss://connect.browserbase.com';
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
getConnectURL({ sessionId, proxy = false } = {}) {
|
|
15
16
|
return `${this.baseConnectURL}?apiKey=${this.apiKey}${sessionId ? `&sessionId=${sessionId}` : ''}${proxy ? `&enableProxy=true` : ''}`;
|
|
16
17
|
}
|
|
17
18
|
async listSessions() {
|
|
@@ -43,17 +44,6 @@ export default class Browserbase {
|
|
|
43
44
|
});
|
|
44
45
|
return await response.json();
|
|
45
46
|
}
|
|
46
|
-
async updateSession(sessionId, options) {
|
|
47
|
-
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}`, {
|
|
48
|
-
method: 'POST',
|
|
49
|
-
headers: {
|
|
50
|
-
'x-bb-api-key': this.apiKey,
|
|
51
|
-
'Content-Type': 'application/json',
|
|
52
|
-
},
|
|
53
|
-
body: JSON.stringify({ projectId: this.projectId, ...options }),
|
|
54
|
-
});
|
|
55
|
-
return await response.json();
|
|
56
|
-
}
|
|
57
47
|
async getSessionRecording(sessionId) {
|
|
58
48
|
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/recording`, {
|
|
59
49
|
headers: {
|
|
@@ -122,7 +112,7 @@ export default class Browserbase {
|
|
|
122
112
|
if (!url) {
|
|
123
113
|
throw new Error('Page URL was not provided');
|
|
124
114
|
}
|
|
125
|
-
const browser = await chromium.connectOverCDP(this.
|
|
115
|
+
const browser = await chromium.connectOverCDP(this.getConnectURL({ sessionId: options.sessionId, proxy: options.proxy }));
|
|
126
116
|
const defaultContext = browser.contexts()[0];
|
|
127
117
|
const page = defaultContext.pages()[0];
|
|
128
118
|
await page.goto(url);
|
|
@@ -143,7 +133,7 @@ export default class Browserbase {
|
|
|
143
133
|
if (!urls.length) {
|
|
144
134
|
throw new Error('Page URLs were not provided');
|
|
145
135
|
}
|
|
146
|
-
const browser = await chromium.connectOverCDP(this.
|
|
136
|
+
const browser = await chromium.connectOverCDP(this.getConnectURL({ sessionId: options.sessionId, proxy: options.proxy }));
|
|
147
137
|
const defaultContext = browser.contexts()[0];
|
|
148
138
|
const page = defaultContext.pages()[0];
|
|
149
139
|
for (const url of urls) {
|
|
@@ -166,7 +156,7 @@ export default class Browserbase {
|
|
|
166
156
|
if (!url) {
|
|
167
157
|
throw new Error('Page URL was not provided');
|
|
168
158
|
}
|
|
169
|
-
const browser = await chromium.connectOverCDP(this.
|
|
159
|
+
const browser = await chromium.connectOverCDP(this.getConnectURL({ sessionId: options.sessionId, proxy: options.proxy }));
|
|
170
160
|
const page = await browser.newPage();
|
|
171
161
|
await page.goto(url);
|
|
172
162
|
const screenshot = await page.screenshot({ fullPage: options.fullPage });
|
|
@@ -174,4 +164,4 @@ export default class Browserbase {
|
|
|
174
164
|
return screenshot;
|
|
175
165
|
}
|
|
176
166
|
}
|
|
177
|
-
export { Browserbase };
|
|
167
|
+
export { Browserbase, BrowserbaseAISDK };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chromium } from 'playwright'
|
|
2
|
+
import BrowserbaseAISDK from './integrations/ai-sdk.js'
|
|
2
3
|
|
|
3
4
|
export type ClientOptions = {
|
|
4
5
|
apiKey?: string
|
|
@@ -43,7 +44,7 @@ export type Session = {
|
|
|
43
44
|
id: string
|
|
44
45
|
createdAt: string
|
|
45
46
|
startedAt: string
|
|
46
|
-
endedAt
|
|
47
|
+
endedAt?: string
|
|
47
48
|
projectId: string
|
|
48
49
|
status?:
|
|
49
50
|
| 'NEW'
|
|
@@ -62,17 +63,18 @@ export type Session = {
|
|
|
62
63
|
logs?: string
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
export type UpdateSessionOptions = {
|
|
66
|
-
projectId?: string
|
|
67
|
-
status: Session['status']
|
|
68
|
-
}
|
|
69
|
-
|
|
70
66
|
export type SessionRecording = {
|
|
71
67
|
type?: string
|
|
72
68
|
time?: string
|
|
73
69
|
data?: object
|
|
74
70
|
}
|
|
75
71
|
|
|
72
|
+
export type DebugConnectionURLs = {
|
|
73
|
+
debuggerFullscreenUrl?: string
|
|
74
|
+
debuggerUrl?: string
|
|
75
|
+
wsUrl?: string
|
|
76
|
+
}
|
|
77
|
+
|
|
76
78
|
export type SessionLog = {
|
|
77
79
|
sessionId?: string
|
|
78
80
|
id: string
|
|
@@ -91,12 +93,6 @@ export type SessionLog = {
|
|
|
91
93
|
pageId?: string
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
export type DebugConnectionURLs = {
|
|
95
|
-
debuggerFullscreenUrl?: string
|
|
96
|
-
debuggerUrl?: string
|
|
97
|
-
wsUrl?: string
|
|
98
|
-
}
|
|
99
|
-
|
|
100
96
|
export default class Browserbase {
|
|
101
97
|
private apiKey: string
|
|
102
98
|
private projectId: string
|
|
@@ -111,7 +107,7 @@ export default class Browserbase {
|
|
|
111
107
|
options.baseConnectURL || 'wss://connect.browserbase.com'
|
|
112
108
|
}
|
|
113
109
|
|
|
114
|
-
|
|
110
|
+
getConnectURL({ sessionId, proxy = false }: ConnectOptions = {}): string {
|
|
115
111
|
return `${this.baseConnectURL}?apiKey=${this.apiKey}${
|
|
116
112
|
sessionId ? `&sessionId=${sessionId}` : ''
|
|
117
113
|
}${proxy ? `&enableProxy=true` : ''}`
|
|
@@ -155,25 +151,6 @@ export default class Browserbase {
|
|
|
155
151
|
return await response.json()
|
|
156
152
|
}
|
|
157
153
|
|
|
158
|
-
async updateSession(
|
|
159
|
-
sessionId: string,
|
|
160
|
-
options: UpdateSessionOptions
|
|
161
|
-
): Promise<Session> {
|
|
162
|
-
const response = await fetch(
|
|
163
|
-
`${this.baseAPIURL}/v1/sessions/${sessionId}`,
|
|
164
|
-
{
|
|
165
|
-
method: 'POST',
|
|
166
|
-
headers: {
|
|
167
|
-
'x-bb-api-key': this.apiKey,
|
|
168
|
-
'Content-Type': 'application/json',
|
|
169
|
-
},
|
|
170
|
-
body: JSON.stringify({ projectId: this.projectId, ...options }),
|
|
171
|
-
}
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
return await response.json()
|
|
175
|
-
}
|
|
176
|
-
|
|
177
154
|
async getSessionRecording(sessionId: string): Promise<SessionRecording[]> {
|
|
178
155
|
const response = await fetch(
|
|
179
156
|
`${this.baseAPIURL}/v1/sessions/${sessionId}/recording`,
|
|
@@ -270,7 +247,7 @@ export default class Browserbase {
|
|
|
270
247
|
}
|
|
271
248
|
|
|
272
249
|
const browser = await chromium.connectOverCDP(
|
|
273
|
-
this.
|
|
250
|
+
this.getConnectURL({ sessionId: options.sessionId, proxy: options.proxy })
|
|
274
251
|
)
|
|
275
252
|
const defaultContext = browser.contexts()[0]
|
|
276
253
|
const page = defaultContext.pages()[0]
|
|
@@ -301,7 +278,7 @@ export default class Browserbase {
|
|
|
301
278
|
}
|
|
302
279
|
|
|
303
280
|
const browser = await chromium.connectOverCDP(
|
|
304
|
-
this.
|
|
281
|
+
this.getConnectURL({ sessionId: options.sessionId, proxy: options.proxy })
|
|
305
282
|
)
|
|
306
283
|
const defaultContext = browser.contexts()[0]
|
|
307
284
|
const page = defaultContext.pages()[0]
|
|
@@ -336,7 +313,7 @@ export default class Browserbase {
|
|
|
336
313
|
}
|
|
337
314
|
|
|
338
315
|
const browser = await chromium.connectOverCDP(
|
|
339
|
-
this.
|
|
316
|
+
this.getConnectURL({ sessionId: options.sessionId, proxy: options.proxy })
|
|
340
317
|
)
|
|
341
318
|
const page = await browser.newPage()
|
|
342
319
|
await page.goto(url)
|
|
@@ -346,4 +323,4 @@ export default class Browserbase {
|
|
|
346
323
|
}
|
|
347
324
|
}
|
|
348
325
|
|
|
349
|
-
export { Browserbase }
|
|
326
|
+
export { Browserbase, BrowserbaseAISDK }
|
package/test/lib.test.ts
CHANGED
|
@@ -23,13 +23,6 @@ describe('Browserbase', () => {
|
|
|
23
23
|
expect(session.id).to.equal(id)
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
-
it('shoud create and update session', async () => {
|
|
27
|
-
const { id } = await browserbase.createSession()
|
|
28
|
-
const updated = await browserbase.updateSession(id, { status: 'RELEASING' })
|
|
29
|
-
|
|
30
|
-
expect(updated.status).to.equal('COMPLETED')
|
|
31
|
-
})
|
|
32
|
-
|
|
33
26
|
it('shoud create a session and retrieve a recording', async () => {
|
|
34
27
|
const { id } = await browserbase.createSession()
|
|
35
28
|
const recording = await browserbase.getSessionRecording(id)
|
|
@@ -42,6 +35,13 @@ describe('Browserbase', () => {
|
|
|
42
35
|
const debug = await browserbase.getDebugConnectionURLs(id)
|
|
43
36
|
})
|
|
44
37
|
|
|
38
|
+
it('shoud create a session and get session logs', async () => {
|
|
39
|
+
const { id } = await browserbase.createSession()
|
|
40
|
+
const logs = await browserbase.getSessionLogs(id)
|
|
41
|
+
|
|
42
|
+
expect(logs.length).to.equal(0)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
45
|
it('should load a webpage', async () => {
|
|
46
46
|
const result = await browserbase.load('https://example.com')
|
|
47
47
|
expect(result).contain('Example Domain')
|