@browserbasehq/sdk 1.1.3 → 1.1.4
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 +11 -14
- package/package.json +1 -1
- package/src/index.ts +18 -22
- package/test/lib.test.ts +5 -0
package/dist/index.d.ts
CHANGED
|
@@ -53,8 +53,8 @@ export type UpdateSessionOptions = {
|
|
|
53
53
|
status: Session['status'];
|
|
54
54
|
};
|
|
55
55
|
export type SessionRecording = {
|
|
56
|
-
type?:
|
|
57
|
-
|
|
56
|
+
type?: string;
|
|
57
|
+
time?: string;
|
|
58
58
|
data?: object;
|
|
59
59
|
};
|
|
60
60
|
export type SessionLog = {
|
|
@@ -91,9 +91,9 @@ export default class Browserbase {
|
|
|
91
91
|
getSession(sessionId: string): Promise<Session>;
|
|
92
92
|
updateSession(sessionId: string, options: UpdateSessionOptions): Promise<Session>;
|
|
93
93
|
getSessionRecording(sessionId: string): Promise<SessionRecording[]>;
|
|
94
|
-
|
|
95
|
-
getSessionDownloads(sessionId: string, filePath: string, retryInterval?: number, retryCount?: number): Promise<void>;
|
|
94
|
+
getSessionDownloads(sessionId: string, retryInterval?: number, retryCount?: number): Promise<Buffer>;
|
|
96
95
|
getDebugConnectionURLs(sessionId: string): Promise<DebugConnectionURLs>;
|
|
96
|
+
getSessionLogs(sessionId: string): Promise<SessionLog[]>;
|
|
97
97
|
load(url: string | string[], options?: LoadOptions): Promise<string> | AsyncGenerator<string, any, unknown>;
|
|
98
98
|
loadURL(url: string, options?: LoadOptions): Promise<string>;
|
|
99
99
|
loadURLs(urls: string[], options?: LoadOptions): AsyncGenerator<string>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { chromium } from 'playwright';
|
|
2
|
-
import fs from 'fs/promises';
|
|
3
2
|
export default class Browserbase {
|
|
4
3
|
apiKey;
|
|
5
4
|
projectId;
|
|
@@ -64,16 +63,7 @@ export default class Browserbase {
|
|
|
64
63
|
});
|
|
65
64
|
return await response.json();
|
|
66
65
|
}
|
|
67
|
-
async
|
|
68
|
-
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/logs`, {
|
|
69
|
-
headers: {
|
|
70
|
-
'x-bb-api-key': this.apiKey,
|
|
71
|
-
'Content-Type': 'application/json',
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
return await response.json();
|
|
75
|
-
}
|
|
76
|
-
async getSessionDownloads(sessionId, filePath, retryInterval = 2000, retryCount = 2) {
|
|
66
|
+
async getSessionDownloads(sessionId, retryInterval = 2000, retryCount = 2) {
|
|
77
67
|
return new Promise((resolve, reject) => {
|
|
78
68
|
const fetchDownload = async () => {
|
|
79
69
|
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/downloads`, {
|
|
@@ -84,9 +74,7 @@ export default class Browserbase {
|
|
|
84
74
|
});
|
|
85
75
|
const arrayBuffer = await response.arrayBuffer();
|
|
86
76
|
if (arrayBuffer.byteLength > 0) {
|
|
87
|
-
|
|
88
|
-
await fs.writeFile(filePath, buffer);
|
|
89
|
-
resolve();
|
|
77
|
+
resolve(Buffer.from(arrayBuffer));
|
|
90
78
|
}
|
|
91
79
|
else {
|
|
92
80
|
retryCount--;
|
|
@@ -110,6 +98,15 @@ export default class Browserbase {
|
|
|
110
98
|
const json = await response.json();
|
|
111
99
|
return json;
|
|
112
100
|
}
|
|
101
|
+
async getSessionLogs(sessionId) {
|
|
102
|
+
const response = await fetch(`${this.baseAPIURL}/v1/sessions/${sessionId}/logs`, {
|
|
103
|
+
headers: {
|
|
104
|
+
'x-bb-api-key': this.apiKey,
|
|
105
|
+
'Content-Type': 'application/json',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
return await response.json();
|
|
109
|
+
}
|
|
113
110
|
load(url, options = {}) {
|
|
114
111
|
if (typeof url === 'string') {
|
|
115
112
|
return this.loadURL(url, options);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { chromium } from 'playwright'
|
|
2
|
-
import fs from 'fs/promises'
|
|
3
2
|
|
|
4
3
|
export type ClientOptions = {
|
|
5
4
|
apiKey?: string
|
|
@@ -69,8 +68,8 @@ export type UpdateSessionOptions = {
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
export type SessionRecording = {
|
|
72
|
-
type?:
|
|
73
|
-
|
|
71
|
+
type?: string
|
|
72
|
+
time?: string
|
|
74
73
|
data?: object
|
|
75
74
|
}
|
|
76
75
|
|
|
@@ -189,27 +188,12 @@ export default class Browserbase {
|
|
|
189
188
|
return await response.json()
|
|
190
189
|
}
|
|
191
190
|
|
|
192
|
-
async getSessionLogs(sessionId: string): Promise<SessionLog[]> {
|
|
193
|
-
const response = await fetch(
|
|
194
|
-
`${this.baseAPIURL}/v1/sessions/${sessionId}/logs`,
|
|
195
|
-
{
|
|
196
|
-
headers: {
|
|
197
|
-
'x-bb-api-key': this.apiKey,
|
|
198
|
-
'Content-Type': 'application/json',
|
|
199
|
-
},
|
|
200
|
-
}
|
|
201
|
-
)
|
|
202
|
-
|
|
203
|
-
return await response.json()
|
|
204
|
-
}
|
|
205
|
-
|
|
206
191
|
async getSessionDownloads(
|
|
207
192
|
sessionId: string,
|
|
208
|
-
filePath: string,
|
|
209
193
|
retryInterval: number = 2000,
|
|
210
194
|
retryCount: number = 2
|
|
211
195
|
) {
|
|
212
|
-
return new Promise<
|
|
196
|
+
return new Promise<Buffer>((resolve, reject) => {
|
|
213
197
|
const fetchDownload = async () => {
|
|
214
198
|
const response = await fetch(
|
|
215
199
|
`${this.baseAPIURL}/v1/sessions/${sessionId}/downloads`,
|
|
@@ -223,9 +207,7 @@ export default class Browserbase {
|
|
|
223
207
|
|
|
224
208
|
const arrayBuffer = await response.arrayBuffer()
|
|
225
209
|
if (arrayBuffer.byteLength > 0) {
|
|
226
|
-
|
|
227
|
-
await fs.writeFile(filePath, buffer)
|
|
228
|
-
resolve()
|
|
210
|
+
resolve(Buffer.from(arrayBuffer))
|
|
229
211
|
} else {
|
|
230
212
|
retryCount--
|
|
231
213
|
if (retryCount <= 0) {
|
|
@@ -258,6 +240,20 @@ export default class Browserbase {
|
|
|
258
240
|
return json
|
|
259
241
|
}
|
|
260
242
|
|
|
243
|
+
async getSessionLogs(sessionId: string): Promise<SessionLog[]> {
|
|
244
|
+
const response = await fetch(
|
|
245
|
+
`${this.baseAPIURL}/v1/sessions/${sessionId}/logs`,
|
|
246
|
+
{
|
|
247
|
+
headers: {
|
|
248
|
+
'x-bb-api-key': this.apiKey,
|
|
249
|
+
'Content-Type': 'application/json',
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
return await response.json()
|
|
255
|
+
}
|
|
256
|
+
|
|
261
257
|
load(url: string | string[], options: LoadOptions = {}) {
|
|
262
258
|
if (typeof url === 'string') {
|
|
263
259
|
return this.loadURL(url, options)
|
package/test/lib.test.ts
CHANGED
|
@@ -10,6 +10,11 @@ describe('Browserbase', () => {
|
|
|
10
10
|
browserbase = new Browserbase()
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
+
it('shoud list sessions', async () => {
|
|
14
|
+
const session = await browserbase.listSessions()
|
|
15
|
+
expect(session[0].status).to.equal('COMPLETED')
|
|
16
|
+
})
|
|
17
|
+
|
|
13
18
|
it('shoud create and retrieve session', async () => {
|
|
14
19
|
const { id } = await browserbase.createSession()
|
|
15
20
|
const session = await browserbase.getSession(id)
|