@browserbasehq/sdk 1.1.2 → 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 CHANGED
@@ -39,45 +39,45 @@ export type Session = {
39
39
  startedAt: string;
40
40
  endedAt: string;
41
41
  projectId: string;
42
- status: 'NEW' | 'CREATED' | 'ERROR' | 'RUNNING' | 'REQUEST_RELEASE' | 'RELEASING';
43
- taskId: string;
44
- proxyBytes: number;
45
- expiresAt: string;
46
- avg_cpu_usage: number;
47
- memory_usage: number;
48
- details: string;
49
- logs: string;
42
+ status?: 'NEW' | 'CREATED' | 'ERROR' | 'RUNNING' | 'REQUEST_RELEASE' | 'RELEASING' | 'COMPLETED';
43
+ taskId?: string;
44
+ proxyBytes?: number;
45
+ expiresAt?: string;
46
+ avg_cpu_usage?: number;
47
+ memory_usage?: number;
48
+ details?: string;
49
+ logs?: string;
50
50
  };
51
51
  export type UpdateSessionOptions = {
52
52
  projectId?: string;
53
53
  status: Session['status'];
54
54
  };
55
55
  export type SessionRecording = {
56
- type: number;
57
- timestamp: number;
58
- data: object;
56
+ type?: string;
57
+ time?: string;
58
+ data?: object;
59
59
  };
60
60
  export type SessionLog = {
61
- sessionId: string;
61
+ sessionId?: string;
62
62
  id: string;
63
- timestamp: string;
64
- method: string;
65
- request: {
66
- timestamp: string;
67
- params: object;
68
- rawBody: string;
63
+ timestamp?: string;
64
+ method?: string;
65
+ request?: {
66
+ timestamp?: string;
67
+ params?: object;
68
+ rawBody?: string;
69
69
  };
70
- response: {
71
- timestamp: string;
72
- result: object;
73
- rawBody: string;
70
+ response?: {
71
+ timestamp?: string;
72
+ result?: object;
73
+ rawBody?: string;
74
74
  };
75
- pageId: string;
75
+ pageId?: string;
76
76
  };
77
77
  export type DebugConnectionURLs = {
78
- debuggerFullscreenUrl: string;
79
- debuggerUrl: string;
80
- wsUrl: string;
78
+ debuggerFullscreenUrl?: string;
79
+ debuggerUrl?: string;
80
+ wsUrl?: string;
81
81
  };
82
82
  export default class Browserbase {
83
83
  private apiKey;
@@ -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
- getSessionLogs(sessionId: string): Promise<SessionLog[]>;
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 getSessionLogs(sessionId) {
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
- const buffer = Buffer.from(arrayBuffer);
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@browserbasehq/sdk",
4
- "version": "1.1.2",
4
+ "version": "1.1.4",
5
5
  "description": "Browserbase JS SDK",
6
6
  "main": "dist/index.js",
7
7
  "scripts": {
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
@@ -46,20 +45,21 @@ export type Session = {
46
45
  startedAt: string
47
46
  endedAt: string
48
47
  projectId: string
49
- status:
48
+ status?:
50
49
  | 'NEW'
51
50
  | 'CREATED'
52
51
  | 'ERROR'
53
52
  | 'RUNNING'
54
53
  | 'REQUEST_RELEASE'
55
54
  | 'RELEASING'
56
- taskId: string
57
- proxyBytes: number
58
- expiresAt: string
59
- avg_cpu_usage: number
60
- memory_usage: number
61
- details: string
62
- logs: string
55
+ | 'COMPLETED'
56
+ taskId?: string
57
+ proxyBytes?: number
58
+ expiresAt?: string
59
+ avg_cpu_usage?: number
60
+ memory_usage?: number
61
+ details?: string
62
+ logs?: string
63
63
  }
64
64
 
65
65
  export type UpdateSessionOptions = {
@@ -68,33 +68,33 @@ export type UpdateSessionOptions = {
68
68
  }
69
69
 
70
70
  export type SessionRecording = {
71
- type: number
72
- timestamp: number
73
- data: object
71
+ type?: string
72
+ time?: string
73
+ data?: object
74
74
  }
75
75
 
76
76
  export type SessionLog = {
77
- sessionId: string
77
+ sessionId?: string
78
78
  id: string
79
- timestamp: string
80
- method: string
81
- request: {
82
- timestamp: string
83
- params: object
84
- rawBody: string
79
+ timestamp?: string
80
+ method?: string
81
+ request?: {
82
+ timestamp?: string
83
+ params?: object
84
+ rawBody?: string
85
85
  }
86
- response: {
87
- timestamp: string
88
- result: object
89
- rawBody: string
86
+ response?: {
87
+ timestamp?: string
88
+ result?: object
89
+ rawBody?: string
90
90
  }
91
- pageId: string
91
+ pageId?: string
92
92
  }
93
93
 
94
94
  export type DebugConnectionURLs = {
95
- debuggerFullscreenUrl: string
96
- debuggerUrl: string
97
- wsUrl: string
95
+ debuggerFullscreenUrl?: string
96
+ debuggerUrl?: string
97
+ wsUrl?: string
98
98
  }
99
99
 
100
100
  export default class Browserbase {
@@ -188,27 +188,12 @@ export default class Browserbase {
188
188
  return await response.json()
189
189
  }
190
190
 
191
- async getSessionLogs(sessionId: string): Promise<SessionLog[]> {
192
- const response = await fetch(
193
- `${this.baseAPIURL}/v1/sessions/${sessionId}/logs`,
194
- {
195
- headers: {
196
- 'x-bb-api-key': this.apiKey,
197
- 'Content-Type': 'application/json',
198
- },
199
- }
200
- )
201
-
202
- return await response.json()
203
- }
204
-
205
191
  async getSessionDownloads(
206
192
  sessionId: string,
207
- filePath: string,
208
193
  retryInterval: number = 2000,
209
194
  retryCount: number = 2
210
195
  ) {
211
- return new Promise<void>((resolve, reject) => {
196
+ return new Promise<Buffer>((resolve, reject) => {
212
197
  const fetchDownload = async () => {
213
198
  const response = await fetch(
214
199
  `${this.baseAPIURL}/v1/sessions/${sessionId}/downloads`,
@@ -222,9 +207,7 @@ export default class Browserbase {
222
207
 
223
208
  const arrayBuffer = await response.arrayBuffer()
224
209
  if (arrayBuffer.byteLength > 0) {
225
- const buffer = Buffer.from(arrayBuffer)
226
- await fs.writeFile(filePath, buffer)
227
- resolve()
210
+ resolve(Buffer.from(arrayBuffer))
228
211
  } else {
229
212
  retryCount--
230
213
  if (retryCount <= 0) {
@@ -257,6 +240,20 @@ export default class Browserbase {
257
240
  return json
258
241
  }
259
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
+
260
257
  load(url: string | string[], options: LoadOptions = {}) {
261
258
  if (typeof url === 'string') {
262
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)