@poncho-ai/browser 0.6.0 → 0.6.1
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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +23 -12
- package/package.json +1 -1
- package/src/session.ts +29 -14
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @poncho-ai/browser@0.6.
|
|
2
|
+
> @poncho-ai/browser@0.6.1 build /Users/cesar/Dev/latitude/poncho-ai/packages/browser
|
|
3
3
|
> tsup src/index.ts --format esm --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
[34mCLI[39m tsup v8.5.1
|
|
8
8
|
[34mCLI[39m Target: es2022
|
|
9
9
|
[34mESM[39m Build start
|
|
10
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
11
|
-
[32mESM[39m ⚡️ Build success in
|
|
10
|
+
[32mESM[39m [1mdist/index.js [22m[32m41.37 KB[39m
|
|
11
|
+
[32mESM[39m ⚡️ Build success in 83ms
|
|
12
12
|
[34mDTS[39m Build start
|
|
13
|
-
[32mDTS[39m ⚡️ Build success in
|
|
14
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m13.
|
|
13
|
+
[32mDTS[39m ⚡️ Build success in 1112ms
|
|
14
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m13.59 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @poncho-ai/browser
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Pass `@sparticuz/chromium` recommended args (--no-sandbox, --disable-gpu, etc.) when launching on serverless platforms. Fixes Chromium sandbox crash on Vercel/Lambda.
|
|
8
|
+
|
|
3
9
|
## 0.6.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -111,10 +111,11 @@ declare class BrowserSession {
|
|
|
111
111
|
private get isRemote();
|
|
112
112
|
private get isServerless();
|
|
113
113
|
/**
|
|
114
|
-
* Resolve executablePath
|
|
115
|
-
*
|
|
114
|
+
* Resolve executablePath and launch args for serverless platforms.
|
|
115
|
+
* When `@sparticuz/chromium` is installed, uses its executable and
|
|
116
|
+
* recommended args (--no-sandbox, --disable-gpu, etc.).
|
|
116
117
|
*/
|
|
117
|
-
private
|
|
118
|
+
private resolveServerlessChromium;
|
|
118
119
|
private launchFreshManager;
|
|
119
120
|
private ensureManager;
|
|
120
121
|
private evictOldestTab;
|
package/dist/index.js
CHANGED
|
@@ -345,12 +345,13 @@ var BrowserSession = class {
|
|
|
345
345
|
return !!(process.env.VERCEL || process.env.AWS_LAMBDA_FUNCTION_NAME || process.env.AWS_EXECUTION_ENV || process.env.SERVERLESS);
|
|
346
346
|
}
|
|
347
347
|
/**
|
|
348
|
-
* Resolve executablePath
|
|
349
|
-
*
|
|
348
|
+
* Resolve executablePath and launch args for serverless platforms.
|
|
349
|
+
* When `@sparticuz/chromium` is installed, uses its executable and
|
|
350
|
+
* recommended args (--no-sandbox, --disable-gpu, etc.).
|
|
350
351
|
*/
|
|
351
|
-
async
|
|
352
|
-
if (this.config.executablePath) return this.config.executablePath;
|
|
353
|
-
if (!this.isServerless) return
|
|
352
|
+
async resolveServerlessChromium() {
|
|
353
|
+
if (this.config.executablePath) return { executablePath: this.config.executablePath };
|
|
354
|
+
if (!this.isServerless) return {};
|
|
354
355
|
try {
|
|
355
356
|
const spec = ["@sparticuz", "chromium"].join("/");
|
|
356
357
|
const mod = await import(
|
|
@@ -358,23 +359,24 @@ var BrowserSession = class {
|
|
|
358
359
|
spec
|
|
359
360
|
);
|
|
360
361
|
const chromium = mod.default ?? mod;
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
362
|
+
const executablePath = await chromium.executablePath();
|
|
363
|
+
const args = Array.isArray(chromium.args) ? chromium.args : [];
|
|
364
|
+
console.log(`[poncho][browser] Auto-detected @sparticuz/chromium: ${executablePath} (${args.length} args)`);
|
|
365
|
+
return { executablePath, args };
|
|
364
366
|
} catch {
|
|
365
|
-
return
|
|
367
|
+
return {};
|
|
366
368
|
}
|
|
367
369
|
}
|
|
368
370
|
async launchFreshManager() {
|
|
369
371
|
const Ctor = await getBrowserManagerCtor();
|
|
370
372
|
const mgr = new Ctor();
|
|
371
373
|
const viewport = this.config.viewport ?? { width: 1280, height: 720 };
|
|
372
|
-
const
|
|
374
|
+
const serverless = await this.resolveServerlessChromium();
|
|
373
375
|
const launchOpts = {
|
|
374
376
|
action: "launch",
|
|
375
377
|
headless: this.config.headless ?? true,
|
|
376
378
|
viewport: { width: viewport.width ?? 1280, height: viewport.height ?? 720 },
|
|
377
|
-
executablePath
|
|
379
|
+
executablePath: serverless.executablePath
|
|
378
380
|
};
|
|
379
381
|
if (this.config.cdpUrl) {
|
|
380
382
|
launchOpts.cdpUrl = this.config.cdpUrl;
|
|
@@ -387,16 +389,25 @@ var BrowserSession = class {
|
|
|
387
389
|
await mkdir(profileDir, { recursive: true });
|
|
388
390
|
launchOpts.profile = profileDir;
|
|
389
391
|
}
|
|
392
|
+
const baseArgs = serverless.args ?? [];
|
|
390
393
|
if (this.stealthEnabled) {
|
|
391
394
|
const ua = this.stealthUserAgent;
|
|
392
395
|
launchOpts.userAgent = ua;
|
|
393
396
|
if (!this.isRemote) {
|
|
394
|
-
|
|
397
|
+
const stealthArgs = buildStealthArgs(ua);
|
|
398
|
+
const merged = [...baseArgs];
|
|
399
|
+
for (const arg of stealthArgs) {
|
|
400
|
+
if (!merged.includes(arg)) merged.push(arg);
|
|
401
|
+
}
|
|
402
|
+
launchOpts.args = merged;
|
|
395
403
|
}
|
|
396
404
|
console.log("[poncho][browser] Launching with stealth mode enabled (UA: " + ua + ")");
|
|
397
405
|
} else if (this.config.userAgent) {
|
|
398
406
|
launchOpts.userAgent = this.config.userAgent;
|
|
399
407
|
}
|
|
408
|
+
if (!launchOpts.args && baseArgs.length > 0) {
|
|
409
|
+
launchOpts.args = baseArgs;
|
|
410
|
+
}
|
|
400
411
|
await mgr.launch(launchOpts);
|
|
401
412
|
this._contextStealthInstalled = false;
|
|
402
413
|
this._uaOverrideApplied.clear();
|
package/package.json
CHANGED
package/src/session.ts
CHANGED
|
@@ -258,23 +258,26 @@ export class BrowserSession {
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
/**
|
|
261
|
-
* Resolve executablePath
|
|
262
|
-
*
|
|
261
|
+
* Resolve executablePath and launch args for serverless platforms.
|
|
262
|
+
* When `@sparticuz/chromium` is installed, uses its executable and
|
|
263
|
+
* recommended args (--no-sandbox, --disable-gpu, etc.).
|
|
263
264
|
*/
|
|
264
|
-
private async
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
private async resolveServerlessChromium(): Promise<{
|
|
266
|
+
executablePath?: string;
|
|
267
|
+
args?: string[];
|
|
268
|
+
}> {
|
|
269
|
+
if (this.config.executablePath) return { executablePath: this.config.executablePath };
|
|
270
|
+
if (!this.isServerless) return {};
|
|
267
271
|
try {
|
|
268
|
-
// Dynamic require — @sparticuz/chromium is an optional peer dependency
|
|
269
|
-
// that the user installs in their agent project for serverless runtimes.
|
|
270
272
|
const spec = ["@sparticuz", "chromium"].join("/");
|
|
271
273
|
const mod = await import(/* webpackIgnore: true */ spec);
|
|
272
274
|
const chromium = mod.default ?? mod;
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
275
|
+
const executablePath = await chromium.executablePath();
|
|
276
|
+
const args: string[] = Array.isArray(chromium.args) ? chromium.args : [];
|
|
277
|
+
console.log(`[poncho][browser] Auto-detected @sparticuz/chromium: ${executablePath} (${args.length} args)`);
|
|
278
|
+
return { executablePath, args };
|
|
276
279
|
} catch {
|
|
277
|
-
return
|
|
280
|
+
return {};
|
|
278
281
|
}
|
|
279
282
|
}
|
|
280
283
|
|
|
@@ -283,13 +286,13 @@ export class BrowserSession {
|
|
|
283
286
|
const mgr = new Ctor();
|
|
284
287
|
|
|
285
288
|
const viewport = this.config.viewport ?? { width: 1280, height: 720 };
|
|
286
|
-
const
|
|
289
|
+
const serverless = await this.resolveServerlessChromium();
|
|
287
290
|
|
|
288
291
|
const launchOpts: Record<string, unknown> = {
|
|
289
292
|
action: "launch",
|
|
290
293
|
headless: this.config.headless ?? true,
|
|
291
294
|
viewport: { width: viewport.width ?? 1280, height: viewport.height ?? 720 },
|
|
292
|
-
executablePath,
|
|
295
|
+
executablePath: serverless.executablePath,
|
|
293
296
|
};
|
|
294
297
|
|
|
295
298
|
if (this.config.cdpUrl) {
|
|
@@ -306,17 +309,29 @@ export class BrowserSession {
|
|
|
306
309
|
launchOpts.profile = profileDir;
|
|
307
310
|
}
|
|
308
311
|
|
|
312
|
+
// Merge args: serverless chromium args (--no-sandbox etc.) + stealth args
|
|
313
|
+
const baseArgs: string[] = serverless.args ?? [];
|
|
314
|
+
|
|
309
315
|
if (this.stealthEnabled) {
|
|
310
316
|
const ua = this.stealthUserAgent!;
|
|
311
317
|
launchOpts.userAgent = ua;
|
|
312
318
|
if (!this.isRemote) {
|
|
313
|
-
|
|
319
|
+
const stealthArgs = buildStealthArgs(ua);
|
|
320
|
+
const merged = [...baseArgs];
|
|
321
|
+
for (const arg of stealthArgs) {
|
|
322
|
+
if (!merged.includes(arg)) merged.push(arg);
|
|
323
|
+
}
|
|
324
|
+
launchOpts.args = merged;
|
|
314
325
|
}
|
|
315
326
|
console.log("[poncho][browser] Launching with stealth mode enabled (UA: " + ua + ")");
|
|
316
327
|
} else if (this.config.userAgent) {
|
|
317
328
|
launchOpts.userAgent = this.config.userAgent;
|
|
318
329
|
}
|
|
319
330
|
|
|
331
|
+
if (!launchOpts.args && baseArgs.length > 0) {
|
|
332
|
+
launchOpts.args = baseArgs;
|
|
333
|
+
}
|
|
334
|
+
|
|
320
335
|
await mgr.launch(launchOpts as Parameters<BrowserManagerInstance["launch"]>[0]);
|
|
321
336
|
|
|
322
337
|
// Reset stealth tracking for fresh browser
|