@browserbasehq/sdk 1.1.6 → 1.1.8
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 +18 -12
- package/dist/index.js +25 -9
- package/package.json +2 -2
- package/src/index.ts +48 -27
- package/test/lib.test.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19,18 +19,24 @@ export type ScreenshotOptions = {
|
|
|
19
19
|
export type CreateSessionOptions = {
|
|
20
20
|
projectId?: string;
|
|
21
21
|
extensionId?: string;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
browserSettings?: {
|
|
23
|
+
fingerprint?: {
|
|
24
|
+
browserListQuery?: string;
|
|
25
|
+
httpVersion?: 1 | 2;
|
|
26
|
+
browsers?: Array<'chrome' | 'firefox' | 'edge' | 'safari'>;
|
|
27
|
+
devices?: Array<'desktop' | 'mobile'>;
|
|
28
|
+
locales?: string[];
|
|
29
|
+
operatingSystems?: Array<'windows' | 'macos' | 'linux' | 'ios' | 'android'>;
|
|
30
|
+
screen?: {
|
|
31
|
+
maxHeight?: number;
|
|
32
|
+
maxWidth?: number;
|
|
33
|
+
minHeight?: number;
|
|
34
|
+
minWidth?: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
viewport?: {
|
|
38
|
+
width?: number;
|
|
39
|
+
height?: number;
|
|
34
40
|
};
|
|
35
41
|
};
|
|
36
42
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import puppeteer from 'puppeteer-core';
|
|
2
2
|
import BrowserbaseAISDK from './integrations/ai-sdk.js';
|
|
3
3
|
export default class Browserbase {
|
|
4
4
|
apiKey;
|
|
@@ -112,9 +112,14 @@ export default class Browserbase {
|
|
|
112
112
|
if (!url) {
|
|
113
113
|
throw new Error('Page URL was not provided');
|
|
114
114
|
}
|
|
115
|
-
const browser = await
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
const browser = await puppeteer.connect({
|
|
116
|
+
browserWSEndpoint: this.getConnectURL({
|
|
117
|
+
sessionId: options.sessionId,
|
|
118
|
+
proxy: options.proxy,
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
const pages = await browser.pages();
|
|
122
|
+
const page = pages[0];
|
|
118
123
|
await page.goto(url);
|
|
119
124
|
let html = await page.content();
|
|
120
125
|
if (options.textContent) {
|
|
@@ -133,9 +138,14 @@ export default class Browserbase {
|
|
|
133
138
|
if (!urls.length) {
|
|
134
139
|
throw new Error('Page URLs were not provided');
|
|
135
140
|
}
|
|
136
|
-
const browser = await
|
|
137
|
-
|
|
138
|
-
|
|
141
|
+
const browser = await puppeteer.connect({
|
|
142
|
+
browserWSEndpoint: this.getConnectURL({
|
|
143
|
+
sessionId: options.sessionId,
|
|
144
|
+
proxy: options.proxy,
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
147
|
+
const pages = await browser.pages();
|
|
148
|
+
const page = pages[0];
|
|
139
149
|
for (const url of urls) {
|
|
140
150
|
await page.goto(url);
|
|
141
151
|
let html = await page.content();
|
|
@@ -156,8 +166,14 @@ export default class Browserbase {
|
|
|
156
166
|
if (!url) {
|
|
157
167
|
throw new Error('Page URL was not provided');
|
|
158
168
|
}
|
|
159
|
-
const browser = await
|
|
160
|
-
|
|
169
|
+
const browser = await puppeteer.connect({
|
|
170
|
+
browserWSEndpoint: this.getConnectURL({
|
|
171
|
+
sessionId: options.sessionId,
|
|
172
|
+
proxy: options.proxy,
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
const pages = await browser.pages();
|
|
176
|
+
const page = pages[0];
|
|
161
177
|
await page.goto(url);
|
|
162
178
|
const screenshot = await page.screenshot({ fullPage: options.fullPage });
|
|
163
179
|
await browser.close();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@browserbasehq/sdk",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.8",
|
|
5
5
|
"description": "Browserbase JS SDK",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/browserbase/js-sdk#readme",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"
|
|
27
|
+
"puppeteer-core": "^22.10.0",
|
|
28
28
|
"zod": "^3.22.5"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import puppeteer from 'puppeteer-core'
|
|
2
2
|
import BrowserbaseAISDK from './integrations/ai-sdk.js'
|
|
3
3
|
|
|
4
4
|
export type ClientOptions = {
|
|
@@ -24,18 +24,26 @@ export type ScreenshotOptions = {
|
|
|
24
24
|
export type CreateSessionOptions = {
|
|
25
25
|
projectId?: string
|
|
26
26
|
extensionId?: string
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
browserSettings?: {
|
|
28
|
+
fingerprint?: {
|
|
29
|
+
browserListQuery?: string
|
|
30
|
+
httpVersion?: 1 | 2
|
|
31
|
+
browsers?: Array<'chrome' | 'firefox' | 'edge' | 'safari'>
|
|
32
|
+
devices?: Array<'desktop' | 'mobile'>
|
|
33
|
+
locales?: string[]
|
|
34
|
+
operatingSystems?: Array<
|
|
35
|
+
'windows' | 'macos' | 'linux' | 'ios' | 'android'
|
|
36
|
+
>
|
|
37
|
+
screen?: {
|
|
38
|
+
maxHeight?: number
|
|
39
|
+
maxWidth?: number
|
|
40
|
+
minHeight?: number
|
|
41
|
+
minWidth?: number
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
viewport?: {
|
|
45
|
+
width?: number
|
|
46
|
+
height?: number
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
}
|
|
@@ -246,11 +254,15 @@ export default class Browserbase {
|
|
|
246
254
|
throw new Error('Page URL was not provided')
|
|
247
255
|
}
|
|
248
256
|
|
|
249
|
-
const browser = await
|
|
250
|
-
this.getConnectURL({
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
257
|
+
const browser = await puppeteer.connect({
|
|
258
|
+
browserWSEndpoint: this.getConnectURL({
|
|
259
|
+
sessionId: options.sessionId,
|
|
260
|
+
proxy: options.proxy,
|
|
261
|
+
}),
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
const pages = await browser.pages()
|
|
265
|
+
const page = pages[0]
|
|
254
266
|
await page.goto(url)
|
|
255
267
|
let html = await page.content()
|
|
256
268
|
|
|
@@ -277,11 +289,15 @@ export default class Browserbase {
|
|
|
277
289
|
throw new Error('Page URLs were not provided')
|
|
278
290
|
}
|
|
279
291
|
|
|
280
|
-
const browser = await
|
|
281
|
-
this.getConnectURL({
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
292
|
+
const browser = await puppeteer.connect({
|
|
293
|
+
browserWSEndpoint: this.getConnectURL({
|
|
294
|
+
sessionId: options.sessionId,
|
|
295
|
+
proxy: options.proxy,
|
|
296
|
+
}),
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
const pages = await browser.pages()
|
|
300
|
+
const page = pages[0]
|
|
285
301
|
|
|
286
302
|
for (const url of urls) {
|
|
287
303
|
await page.goto(url)
|
|
@@ -312,10 +328,15 @@ export default class Browserbase {
|
|
|
312
328
|
throw new Error('Page URL was not provided')
|
|
313
329
|
}
|
|
314
330
|
|
|
315
|
-
const browser = await
|
|
316
|
-
this.getConnectURL({
|
|
317
|
-
|
|
318
|
-
|
|
331
|
+
const browser = await puppeteer.connect({
|
|
332
|
+
browserWSEndpoint: this.getConnectURL({
|
|
333
|
+
sessionId: options.sessionId,
|
|
334
|
+
proxy: options.proxy,
|
|
335
|
+
}),
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
const pages = await browser.pages()
|
|
339
|
+
const page = pages[0]
|
|
319
340
|
await page.goto(url)
|
|
320
341
|
const screenshot = await page.screenshot({ fullPage: options.fullPage })
|
|
321
342
|
await browser.close()
|
package/test/lib.test.ts
CHANGED
|
@@ -66,7 +66,7 @@ describe('Browserbase', () => {
|
|
|
66
66
|
|
|
67
67
|
it('should take a screenshot', { timeout: 10000 }, async () => {
|
|
68
68
|
const result = await browserbase.screenshot('https://example.com')
|
|
69
|
-
expect(result.length).to.equal(
|
|
69
|
+
expect(result.length).to.equal(27040)
|
|
70
70
|
})
|
|
71
71
|
|
|
72
72
|
it('should work with AI SDK', async () => {
|