@browserbasehq/sdk 1.1.7 → 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.js +25 -9
- package/package.json +2 -2
- package/src/index.ts +31 -16
- package/test/lib.test.ts +1 -1
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 = {
|
|
@@ -31,7 +31,9 @@ export type CreateSessionOptions = {
|
|
|
31
31
|
browsers?: Array<'chrome' | 'firefox' | 'edge' | 'safari'>
|
|
32
32
|
devices?: Array<'desktop' | 'mobile'>
|
|
33
33
|
locales?: string[]
|
|
34
|
-
operatingSystems?: Array<
|
|
34
|
+
operatingSystems?: Array<
|
|
35
|
+
'windows' | 'macos' | 'linux' | 'ios' | 'android'
|
|
36
|
+
>
|
|
35
37
|
screen?: {
|
|
36
38
|
maxHeight?: number
|
|
37
39
|
maxWidth?: number
|
|
@@ -252,11 +254,15 @@ export default class Browserbase {
|
|
|
252
254
|
throw new Error('Page URL was not provided')
|
|
253
255
|
}
|
|
254
256
|
|
|
255
|
-
const browser = await
|
|
256
|
-
this.getConnectURL({
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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]
|
|
260
266
|
await page.goto(url)
|
|
261
267
|
let html = await page.content()
|
|
262
268
|
|
|
@@ -283,11 +289,15 @@ export default class Browserbase {
|
|
|
283
289
|
throw new Error('Page URLs were not provided')
|
|
284
290
|
}
|
|
285
291
|
|
|
286
|
-
const browser = await
|
|
287
|
-
this.getConnectURL({
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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]
|
|
291
301
|
|
|
292
302
|
for (const url of urls) {
|
|
293
303
|
await page.goto(url)
|
|
@@ -318,10 +328,15 @@ export default class Browserbase {
|
|
|
318
328
|
throw new Error('Page URL was not provided')
|
|
319
329
|
}
|
|
320
330
|
|
|
321
|
-
const browser = await
|
|
322
|
-
this.getConnectURL({
|
|
323
|
-
|
|
324
|
-
|
|
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]
|
|
325
340
|
await page.goto(url)
|
|
326
341
|
const screenshot = await page.screenshot({ fullPage: options.fullPage })
|
|
327
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 () => {
|