@browserbasehq/sdk 1.1.7 → 1.1.9
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 +1 -1
- package/dist/index.js +36 -12
- package/dist/integrations/ai-sdk.js +9 -5
- package/package.json +2 -3
- package/src/index.ts +31 -16
- package/test/lib.test.ts +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BrowserbaseAISDK = exports.Browserbase = void 0;
|
|
7
|
+
const puppeteer_core_1 = __importDefault(require("puppeteer-core"));
|
|
8
|
+
const ai_sdk_js_1 = __importDefault(require("./integrations/ai-sdk.js"));
|
|
9
|
+
exports.BrowserbaseAISDK = ai_sdk_js_1.default;
|
|
10
|
+
class Browserbase {
|
|
4
11
|
apiKey;
|
|
5
12
|
projectId;
|
|
6
13
|
baseAPIURL;
|
|
@@ -112,9 +119,14 @@ export default class Browserbase {
|
|
|
112
119
|
if (!url) {
|
|
113
120
|
throw new Error('Page URL was not provided');
|
|
114
121
|
}
|
|
115
|
-
const browser = await
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
const browser = await puppeteer_core_1.default.connect({
|
|
123
|
+
browserWSEndpoint: this.getConnectURL({
|
|
124
|
+
sessionId: options.sessionId,
|
|
125
|
+
proxy: options.proxy,
|
|
126
|
+
}),
|
|
127
|
+
});
|
|
128
|
+
const pages = await browser.pages();
|
|
129
|
+
const page = pages[0];
|
|
118
130
|
await page.goto(url);
|
|
119
131
|
let html = await page.content();
|
|
120
132
|
if (options.textContent) {
|
|
@@ -133,9 +145,14 @@ export default class Browserbase {
|
|
|
133
145
|
if (!urls.length) {
|
|
134
146
|
throw new Error('Page URLs were not provided');
|
|
135
147
|
}
|
|
136
|
-
const browser = await
|
|
137
|
-
|
|
138
|
-
|
|
148
|
+
const browser = await puppeteer_core_1.default.connect({
|
|
149
|
+
browserWSEndpoint: this.getConnectURL({
|
|
150
|
+
sessionId: options.sessionId,
|
|
151
|
+
proxy: options.proxy,
|
|
152
|
+
}),
|
|
153
|
+
});
|
|
154
|
+
const pages = await browser.pages();
|
|
155
|
+
const page = pages[0];
|
|
139
156
|
for (const url of urls) {
|
|
140
157
|
await page.goto(url);
|
|
141
158
|
let html = await page.content();
|
|
@@ -156,12 +173,19 @@ export default class Browserbase {
|
|
|
156
173
|
if (!url) {
|
|
157
174
|
throw new Error('Page URL was not provided');
|
|
158
175
|
}
|
|
159
|
-
const browser = await
|
|
160
|
-
|
|
176
|
+
const browser = await puppeteer_core_1.default.connect({
|
|
177
|
+
browserWSEndpoint: this.getConnectURL({
|
|
178
|
+
sessionId: options.sessionId,
|
|
179
|
+
proxy: options.proxy,
|
|
180
|
+
}),
|
|
181
|
+
});
|
|
182
|
+
const pages = await browser.pages();
|
|
183
|
+
const page = pages[0];
|
|
161
184
|
await page.goto(url);
|
|
162
185
|
const screenshot = await page.screenshot({ fullPage: options.fullPage });
|
|
163
186
|
await browser.close();
|
|
164
187
|
return screenshot;
|
|
165
188
|
}
|
|
166
189
|
}
|
|
167
|
-
|
|
190
|
+
exports.default = Browserbase;
|
|
191
|
+
exports.Browserbase = Browserbase;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BrowserbaseAISDK = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
function BrowserbaseAISDK(b, options = {}) {
|
|
3
6
|
return {
|
|
4
7
|
description: 'Load a webpage in a browser hosted by Browserbase and return its contents',
|
|
5
|
-
parameters: z.object({
|
|
6
|
-
url: z.string().describe('Page URL to be loaded'),
|
|
8
|
+
parameters: zod_1.z.object({
|
|
9
|
+
url: zod_1.z.string().describe('Page URL to be loaded'),
|
|
7
10
|
}),
|
|
8
11
|
execute: async ({ url }) => {
|
|
9
12
|
const page = await b.loadURL(url, options);
|
|
@@ -11,4 +14,5 @@ export default function BrowserbaseAISDK(b, options = {}) {
|
|
|
11
14
|
},
|
|
12
15
|
};
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
exports.default = BrowserbaseAISDK;
|
|
18
|
+
exports.BrowserbaseAISDK = BrowserbaseAISDK;
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"type": "module",
|
|
3
2
|
"name": "@browserbasehq/sdk",
|
|
4
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
5
4
|
"description": "Browserbase JS SDK",
|
|
6
5
|
"main": "dist/index.js",
|
|
7
6
|
"scripts": {
|
|
@@ -24,7 +23,7 @@
|
|
|
24
23
|
},
|
|
25
24
|
"homepage": "https://github.com/browserbase/js-sdk#readme",
|
|
26
25
|
"dependencies": {
|
|
27
|
-
"
|
|
26
|
+
"puppeteer-core": "^22.10.0",
|
|
28
27
|
"zod": "^3.22.5"
|
|
29
28
|
},
|
|
30
29
|
"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 () => {
|