@browserbasehq/sdk 1.1.1 → 1.1.2
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 +4 -4
- package/dist/index.js +18 -18
- package/dist/integrations/ai-sdk.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +18 -18
- package/src/integrations/ai-sdk.ts +1 -1
- package/test/lib.test.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -82,10 +82,10 @@ export type DebugConnectionURLs = {
|
|
|
82
82
|
export default class Browserbase {
|
|
83
83
|
private apiKey;
|
|
84
84
|
private projectId;
|
|
85
|
-
private
|
|
85
|
+
private baseAPIURL;
|
|
86
86
|
private baseConnectURL;
|
|
87
87
|
constructor(options?: ClientOptions);
|
|
88
|
-
|
|
88
|
+
connectURL({ sessionId, proxy }?: ConnectOptions): string;
|
|
89
89
|
listSessions(): Promise<Session[]>;
|
|
90
90
|
createSession(options?: CreateSessionOptions): Promise<Session>;
|
|
91
91
|
getSession(sessionId: string): Promise<Session>;
|
|
@@ -95,8 +95,8 @@ export default class Browserbase {
|
|
|
95
95
|
getSessionDownloads(sessionId: string, filePath: string, retryInterval?: number, retryCount?: number): Promise<void>;
|
|
96
96
|
getDebugConnectionURLs(sessionId: string): Promise<DebugConnectionURLs>;
|
|
97
97
|
load(url: string | string[], options?: LoadOptions): Promise<string> | AsyncGenerator<string, any, unknown>;
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
loadURL(url: string, options?: LoadOptions): Promise<string>;
|
|
99
|
+
loadURLs(urls: string[], options?: LoadOptions): AsyncGenerator<string>;
|
|
100
100
|
screenshot(url: string, options?: ScreenshotOptions): Promise<Buffer>;
|
|
101
101
|
}
|
|
102
102
|
export { Browserbase };
|
package/dist/index.js
CHANGED
|
@@ -3,20 +3,20 @@ import fs from 'fs/promises';
|
|
|
3
3
|
export default class Browserbase {
|
|
4
4
|
apiKey;
|
|
5
5
|
projectId;
|
|
6
|
-
|
|
6
|
+
baseAPIURL;
|
|
7
7
|
baseConnectURL;
|
|
8
8
|
constructor(options = {}) {
|
|
9
9
|
this.apiKey = options.apiKey || process.env.BROWSERBASE_API_KEY;
|
|
10
10
|
this.projectId = options.projectId || process.env.BROWSERBASE_PROJECT_ID;
|
|
11
|
-
this.
|
|
11
|
+
this.baseAPIURL = options.baseURL || 'https://www.browserbase.com';
|
|
12
12
|
this.baseConnectURL =
|
|
13
13
|
options.baseConnectURL || 'wss://connect.browserbase.com';
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
connectURL({ sessionId, proxy = false } = {}) {
|
|
16
16
|
return `${this.baseConnectURL}?apiKey=${this.apiKey}${sessionId ? `&sessionId=${sessionId}` : ''}${proxy ? `&enableProxy=true` : ''}`;
|
|
17
17
|
}
|
|
18
18
|
async listSessions() {
|
|
19
|
-
const response = await fetch(`${this.
|
|
19
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions`, {
|
|
20
20
|
headers: {
|
|
21
21
|
'x-bb-api-key': this.apiKey,
|
|
22
22
|
'Content-Type': 'application/json',
|
|
@@ -25,7 +25,7 @@ export default class Browserbase {
|
|
|
25
25
|
return await response.json();
|
|
26
26
|
}
|
|
27
27
|
async createSession(options) {
|
|
28
|
-
const response = await fetch(`${this.
|
|
28
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions`, {
|
|
29
29
|
method: 'POST',
|
|
30
30
|
headers: {
|
|
31
31
|
'x-bb-api-key': this.apiKey,
|
|
@@ -36,7 +36,7 @@ export default class Browserbase {
|
|
|
36
36
|
return await response.json();
|
|
37
37
|
}
|
|
38
38
|
async getSession(sessionId) {
|
|
39
|
-
const response = await fetch(`${this.
|
|
39
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}`, {
|
|
40
40
|
headers: {
|
|
41
41
|
'x-bb-api-key': this.apiKey,
|
|
42
42
|
'Content-Type': 'application/json',
|
|
@@ -45,7 +45,7 @@ export default class Browserbase {
|
|
|
45
45
|
return await response.json();
|
|
46
46
|
}
|
|
47
47
|
async updateSession(sessionId, options) {
|
|
48
|
-
const response = await fetch(`${this.
|
|
48
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}`, {
|
|
49
49
|
method: 'POST',
|
|
50
50
|
headers: {
|
|
51
51
|
'x-bb-api-key': this.apiKey,
|
|
@@ -56,7 +56,7 @@ export default class Browserbase {
|
|
|
56
56
|
return await response.json();
|
|
57
57
|
}
|
|
58
58
|
async getSessionRecording(sessionId) {
|
|
59
|
-
const response = await fetch(`${this.
|
|
59
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/recording`, {
|
|
60
60
|
headers: {
|
|
61
61
|
'x-bb-api-key': this.apiKey,
|
|
62
62
|
'Content-Type': 'application/json',
|
|
@@ -65,7 +65,7 @@ export default class Browserbase {
|
|
|
65
65
|
return await response.json();
|
|
66
66
|
}
|
|
67
67
|
async getSessionLogs(sessionId) {
|
|
68
|
-
const response = await fetch(`${this.
|
|
68
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/logs`, {
|
|
69
69
|
headers: {
|
|
70
70
|
'x-bb-api-key': this.apiKey,
|
|
71
71
|
'Content-Type': 'application/json',
|
|
@@ -76,7 +76,7 @@ export default class Browserbase {
|
|
|
76
76
|
async getSessionDownloads(sessionId, filePath, retryInterval = 2000, retryCount = 2) {
|
|
77
77
|
return new Promise((resolve, reject) => {
|
|
78
78
|
const fetchDownload = async () => {
|
|
79
|
-
const response = await fetch(`${this.
|
|
79
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/downloads`, {
|
|
80
80
|
method: 'GET',
|
|
81
81
|
headers: {
|
|
82
82
|
'x-bb-api-key': this.apiKey,
|
|
@@ -100,7 +100,7 @@ export default class Browserbase {
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
async getDebugConnectionURLs(sessionId) {
|
|
103
|
-
const response = await fetch(`${this.
|
|
103
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/debug`, {
|
|
104
104
|
method: 'GET',
|
|
105
105
|
headers: {
|
|
106
106
|
'x-bb-api-key': this.apiKey,
|
|
@@ -112,20 +112,20 @@ export default class Browserbase {
|
|
|
112
112
|
}
|
|
113
113
|
load(url, options = {}) {
|
|
114
114
|
if (typeof url === 'string') {
|
|
115
|
-
return this.
|
|
115
|
+
return this.loadURL(url, options);
|
|
116
116
|
}
|
|
117
117
|
else if (Array.isArray(url)) {
|
|
118
|
-
return this.
|
|
118
|
+
return this.loadURLs(url, options);
|
|
119
119
|
}
|
|
120
120
|
else {
|
|
121
121
|
throw new TypeError('Input must be a URL string or array of URLs');
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
async
|
|
124
|
+
async loadURL(url, options = {}) {
|
|
125
125
|
if (!url) {
|
|
126
126
|
throw new Error('Page URL was not provided');
|
|
127
127
|
}
|
|
128
|
-
const browser = await chromium.connectOverCDP(this.
|
|
128
|
+
const browser = await chromium.connectOverCDP(this.connectURL({ sessionId: options.sessionId, proxy: options.proxy }));
|
|
129
129
|
const defaultContext = browser.contexts()[0];
|
|
130
130
|
const page = defaultContext.pages()[0];
|
|
131
131
|
await page.goto(url);
|
|
@@ -142,11 +142,11 @@ export default class Browserbase {
|
|
|
142
142
|
await browser.close();
|
|
143
143
|
return html;
|
|
144
144
|
}
|
|
145
|
-
async *
|
|
145
|
+
async *loadURLs(urls, options = {}) {
|
|
146
146
|
if (!urls.length) {
|
|
147
147
|
throw new Error('Page URLs were not provided');
|
|
148
148
|
}
|
|
149
|
-
const browser = await chromium.connectOverCDP(this.
|
|
149
|
+
const browser = await chromium.connectOverCDP(this.connectURL({ sessionId: options.sessionId, proxy: options.proxy }));
|
|
150
150
|
const defaultContext = browser.contexts()[0];
|
|
151
151
|
const page = defaultContext.pages()[0];
|
|
152
152
|
for (const url of urls) {
|
|
@@ -169,7 +169,7 @@ export default class Browserbase {
|
|
|
169
169
|
if (!url) {
|
|
170
170
|
throw new Error('Page URL was not provided');
|
|
171
171
|
}
|
|
172
|
-
const browser = await chromium.connectOverCDP(this.
|
|
172
|
+
const browser = await chromium.connectOverCDP(this.connectURL({ sessionId: options.sessionId, proxy: options.proxy }));
|
|
173
173
|
const page = await browser.newPage();
|
|
174
174
|
await page.goto(url);
|
|
175
175
|
const screenshot = await page.screenshot({ fullPage: options.fullPage });
|
|
@@ -6,7 +6,7 @@ export default function BrowserbaseAISDK(b, options = {}) {
|
|
|
6
6
|
url: z.string().describe('Page URL to be loaded'),
|
|
7
7
|
}),
|
|
8
8
|
execute: async ({ url }) => {
|
|
9
|
-
const page = await b.
|
|
9
|
+
const page = await b.loadURL(url, options);
|
|
10
10
|
return { page };
|
|
11
11
|
},
|
|
12
12
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -100,25 +100,25 @@ export type DebugConnectionURLs = {
|
|
|
100
100
|
export default class Browserbase {
|
|
101
101
|
private apiKey: string
|
|
102
102
|
private projectId: string
|
|
103
|
-
private
|
|
103
|
+
private baseAPIURL: string
|
|
104
104
|
private baseConnectURL: string
|
|
105
105
|
|
|
106
106
|
constructor(options: ClientOptions = {}) {
|
|
107
107
|
this.apiKey = options.apiKey || process.env.BROWSERBASE_API_KEY!
|
|
108
108
|
this.projectId = options.projectId || process.env.BROWSERBASE_PROJECT_ID!
|
|
109
|
-
this.
|
|
109
|
+
this.baseAPIURL = options.baseURL || 'https://www.browserbase.com'
|
|
110
110
|
this.baseConnectURL =
|
|
111
111
|
options.baseConnectURL || 'wss://connect.browserbase.com'
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
connectURL({ sessionId, proxy = false }: ConnectOptions = {}): string {
|
|
115
115
|
return `${this.baseConnectURL}?apiKey=${this.apiKey}${
|
|
116
116
|
sessionId ? `&sessionId=${sessionId}` : ''
|
|
117
117
|
}${proxy ? `&enableProxy=true` : ''}`
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
async listSessions(): Promise<Session[]> {
|
|
121
|
-
const response = await fetch(`${this.
|
|
121
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions`, {
|
|
122
122
|
headers: {
|
|
123
123
|
'x-bb-api-key': this.apiKey,
|
|
124
124
|
'Content-Type': 'application/json',
|
|
@@ -129,7 +129,7 @@ export default class Browserbase {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
async createSession(options?: CreateSessionOptions): Promise<Session> {
|
|
132
|
-
const response = await fetch(`${this.
|
|
132
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions`, {
|
|
133
133
|
method: 'POST',
|
|
134
134
|
headers: {
|
|
135
135
|
'x-bb-api-key': this.apiKey,
|
|
@@ -143,7 +143,7 @@ export default class Browserbase {
|
|
|
143
143
|
|
|
144
144
|
async getSession(sessionId: string): Promise<Session> {
|
|
145
145
|
const response = await fetch(
|
|
146
|
-
`${this.
|
|
146
|
+
`${this.baseAPIURL}/v1/sessions/${sessionId}`,
|
|
147
147
|
{
|
|
148
148
|
headers: {
|
|
149
149
|
'x-bb-api-key': this.apiKey,
|
|
@@ -160,7 +160,7 @@ export default class Browserbase {
|
|
|
160
160
|
options: UpdateSessionOptions
|
|
161
161
|
): Promise<Session> {
|
|
162
162
|
const response = await fetch(
|
|
163
|
-
`${this.
|
|
163
|
+
`${this.baseAPIURL}/v1/sessions/${sessionId}`,
|
|
164
164
|
{
|
|
165
165
|
method: 'POST',
|
|
166
166
|
headers: {
|
|
@@ -176,7 +176,7 @@ export default class Browserbase {
|
|
|
176
176
|
|
|
177
177
|
async getSessionRecording(sessionId: string): Promise<SessionRecording[]> {
|
|
178
178
|
const response = await fetch(
|
|
179
|
-
`${this.
|
|
179
|
+
`${this.baseAPIURL}/v1/sessions/${sessionId}/recording`,
|
|
180
180
|
{
|
|
181
181
|
headers: {
|
|
182
182
|
'x-bb-api-key': this.apiKey,
|
|
@@ -190,7 +190,7 @@ export default class Browserbase {
|
|
|
190
190
|
|
|
191
191
|
async getSessionLogs(sessionId: string): Promise<SessionLog[]> {
|
|
192
192
|
const response = await fetch(
|
|
193
|
-
`${this.
|
|
193
|
+
`${this.baseAPIURL}/v1/sessions/${sessionId}/logs`,
|
|
194
194
|
{
|
|
195
195
|
headers: {
|
|
196
196
|
'x-bb-api-key': this.apiKey,
|
|
@@ -211,7 +211,7 @@ export default class Browserbase {
|
|
|
211
211
|
return new Promise<void>((resolve, reject) => {
|
|
212
212
|
const fetchDownload = async () => {
|
|
213
213
|
const response = await fetch(
|
|
214
|
-
`${this.
|
|
214
|
+
`${this.baseAPIURL}/v1/sessions/${sessionId}/downloads`,
|
|
215
215
|
{
|
|
216
216
|
method: 'GET',
|
|
217
217
|
headers: {
|
|
@@ -243,7 +243,7 @@ export default class Browserbase {
|
|
|
243
243
|
sessionId: string
|
|
244
244
|
): Promise<DebugConnectionURLs> {
|
|
245
245
|
const response = await fetch(
|
|
246
|
-
`${this.
|
|
246
|
+
`${this.baseAPIURL}/v1/sessions/${sessionId}/debug`,
|
|
247
247
|
{
|
|
248
248
|
method: 'GET',
|
|
249
249
|
headers: {
|
|
@@ -259,21 +259,21 @@ export default class Browserbase {
|
|
|
259
259
|
|
|
260
260
|
load(url: string | string[], options: LoadOptions = {}) {
|
|
261
261
|
if (typeof url === 'string') {
|
|
262
|
-
return this.
|
|
262
|
+
return this.loadURL(url, options)
|
|
263
263
|
} else if (Array.isArray(url)) {
|
|
264
|
-
return this.
|
|
264
|
+
return this.loadURLs(url, options)
|
|
265
265
|
} else {
|
|
266
266
|
throw new TypeError('Input must be a URL string or array of URLs')
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
async
|
|
270
|
+
async loadURL(url: string, options: LoadOptions = {}): Promise<string> {
|
|
271
271
|
if (!url) {
|
|
272
272
|
throw new Error('Page URL was not provided')
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
const browser = await chromium.connectOverCDP(
|
|
276
|
-
this.
|
|
276
|
+
this.connectURL({ sessionId: options.sessionId, proxy: options.proxy })
|
|
277
277
|
)
|
|
278
278
|
const defaultContext = browser.contexts()[0]
|
|
279
279
|
const page = defaultContext.pages()[0]
|
|
@@ -295,7 +295,7 @@ export default class Browserbase {
|
|
|
295
295
|
return html
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
async *
|
|
298
|
+
async *loadURLs(
|
|
299
299
|
urls: string[],
|
|
300
300
|
options: LoadOptions = {}
|
|
301
301
|
): AsyncGenerator<string> {
|
|
@@ -304,7 +304,7 @@ export default class Browserbase {
|
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
const browser = await chromium.connectOverCDP(
|
|
307
|
-
this.
|
|
307
|
+
this.connectURL({ sessionId: options.sessionId, proxy: options.proxy })
|
|
308
308
|
)
|
|
309
309
|
const defaultContext = browser.contexts()[0]
|
|
310
310
|
const page = defaultContext.pages()[0]
|
|
@@ -339,7 +339,7 @@ export default class Browserbase {
|
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
const browser = await chromium.connectOverCDP(
|
|
342
|
-
this.
|
|
342
|
+
this.connectURL({ sessionId: options.sessionId, proxy: options.proxy })
|
|
343
343
|
)
|
|
344
344
|
const page = await browser.newPage()
|
|
345
345
|
await page.goto(url)
|
|
@@ -12,7 +12,7 @@ export default function BrowserbaseAISDK(
|
|
|
12
12
|
url: z.string().describe('Page URL to be loaded'),
|
|
13
13
|
}),
|
|
14
14
|
execute: async ({ url }: { url: string }) => {
|
|
15
|
-
const page = await b.
|
|
15
|
+
const page = await b.loadURL(url, options)
|
|
16
16
|
return { page }
|
|
17
17
|
},
|
|
18
18
|
}
|
package/test/lib.test.ts
CHANGED
|
@@ -51,7 +51,7 @@ describe('Browserbase', () => {
|
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
it('should load URLs', async () => {
|
|
54
|
-
const result = await browserbase.
|
|
54
|
+
const result = await browserbase.loadURLs(['https://example.com'])
|
|
55
55
|
const page = await result.next()
|
|
56
56
|
|
|
57
57
|
// finish iterator
|