@browserbasehq/stagehand 3.0.6-alpha-45bcef0e5788b083f9e38dfd7c3bc63afcd4b6dd → 3.0.6-alpha-bb85ad912738623a7a866f0cb6e8d5807c6c2738

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
@@ -863,6 +863,10 @@ interface ZodPathSegments {
863
863
  */
864
864
  segments: Array<string | number>;
865
865
  }
866
+ type InitScriptSource<Arg> = string | {
867
+ path?: string;
868
+ content?: string;
869
+ } | ((arg: Arg) => unknown);
866
870
 
867
871
  type EvaluateOptions = {
868
872
  /** The question to ask about the task state */
@@ -927,10 +931,6 @@ declare class StagehandAPIClient {
927
931
  private request;
928
932
  }
929
933
 
930
- type InitScriptSource<Arg> = string | {
931
- path?: string;
932
- content?: string;
933
- } | ((arg: Arg) => unknown);
934
934
  /**
935
935
  * V3Context
936
936
  *
@@ -1300,6 +1300,7 @@ declare class Page {
1300
1300
  private ensureCursorScript;
1301
1301
  enableCursorOverlay(): Promise<void>;
1302
1302
  private updateCursor;
1303
+ addInitScript<Arg>(script: InitScriptSource<Arg>, arg?: Arg): Promise<void>;
1303
1304
  /**
1304
1305
  * Factory: create Page and seed registry with the shallow tree from Page.getFrameTree.
1305
1306
  * Assumes Page domain is already enabled on the session passed in.
package/dist/index.js CHANGED
@@ -141,7 +141,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
141
141
  var STAGEHAND_VERSION;
142
142
  var init_version = __esm({
143
143
  "lib/version.ts"() {
144
- STAGEHAND_VERSION = "3.0.6-alpha-45bcef0e5788b083f9e38dfd7c3bc63afcd4b6dd";
144
+ STAGEHAND_VERSION = "3.0.6-alpha-bb85ad912738623a7a866f0cb6e8d5807c6c2738";
145
145
  }
146
146
  });
147
147
 
@@ -24004,6 +24004,52 @@ var init_navigationResponseTracker = __esm({
24004
24004
  }
24005
24005
  });
24006
24006
 
24007
+ // lib/v3/understudy/initScripts.ts
24008
+ function appendSourceURL(source, filePath) {
24009
+ const sanitized = filePath.replace(/\n/g, "");
24010
+ return `${source}
24011
+ //# sourceURL=${sanitized}`;
24012
+ }
24013
+ function normalizeInitScriptSource(_0, _1) {
24014
+ return __async(this, arguments, function* (script, arg, caller = DEFAULT_CALLER) {
24015
+ if (typeof script === "function") {
24016
+ const argString = Object.is(arg, void 0) ? "undefined" : JSON.stringify(arg);
24017
+ return `(${script.toString()})(${argString})`;
24018
+ }
24019
+ if (!Object.is(arg, void 0)) {
24020
+ throw new StagehandInvalidArgumentError(
24021
+ `${caller}: 'arg' is only supported when passing a function.`
24022
+ );
24023
+ }
24024
+ if (typeof script === "string") {
24025
+ return script;
24026
+ }
24027
+ if (!script || typeof script !== "object") {
24028
+ throw new StagehandInvalidArgumentError(
24029
+ `${caller}: provide a string, function, or an object with path/content.`
24030
+ );
24031
+ }
24032
+ if (typeof script.content === "string") {
24033
+ return script.content;
24034
+ }
24035
+ if (typeof script.path === "string" && script.path.trim()) {
24036
+ const raw = yield import_fs6.promises.readFile(script.path, "utf8");
24037
+ return appendSourceURL(raw, script.path);
24038
+ }
24039
+ throw new StagehandInvalidArgumentError(
24040
+ `${caller}: provide a string, function, or an object with path/content.`
24041
+ );
24042
+ });
24043
+ }
24044
+ var import_fs6, DEFAULT_CALLER;
24045
+ var init_initScripts = __esm({
24046
+ "lib/v3/understudy/initScripts.ts"() {
24047
+ import_fs6 = require("fs");
24048
+ init_sdkErrors();
24049
+ DEFAULT_CALLER = "context.addInitScript";
24050
+ }
24051
+ });
24052
+
24007
24053
  // lib/v3/understudy/screenshotUtils.ts
24008
24054
  function collectFramesForScreenshot(page) {
24009
24055
  const seen = /* @__PURE__ */ new Map();
@@ -24327,10 +24373,10 @@ var page_exports = {};
24327
24373
  __export(page_exports, {
24328
24374
  Page: () => Page
24329
24375
  });
24330
- var import_fs6, LIFECYCLE_NAME, Page;
24376
+ var import_fs7, LIFECYCLE_NAME, Page;
24331
24377
  var init_page = __esm({
24332
24378
  "lib/v3/understudy/page.ts"() {
24333
- import_fs6 = require("fs");
24379
+ import_fs7 = require("fs");
24334
24380
  init_logger();
24335
24381
  init_frame();
24336
24382
  init_frameLocator();
@@ -24344,6 +24390,7 @@ var init_page = __esm({
24344
24390
  init_response2();
24345
24391
  init_consoleMessage();
24346
24392
  init_sdkErrors();
24393
+ init_initScripts();
24347
24394
  init_screenshotUtils();
24348
24395
  LIFECYCLE_NAME = {
24349
24396
  load: "load",
@@ -24511,6 +24558,16 @@ var init_page = __esm({
24511
24558
  }
24512
24559
  });
24513
24560
  }
24561
+ addInitScript(script, arg) {
24562
+ return __async(this, null, function* () {
24563
+ const source = yield normalizeInitScriptSource(
24564
+ script,
24565
+ arg,
24566
+ "page.addInitScript"
24567
+ );
24568
+ yield this.registerInitScript(source);
24569
+ });
24570
+ }
24514
24571
  /**
24515
24572
  * Factory: create Page and seed registry with the shallow tree from Page.getFrameTree.
24516
24573
  * Assumes Page domain is already enabled on the session passed in.
@@ -25209,7 +25266,7 @@ var init_page = __esm({
25209
25266
  scale: captureScale
25210
25267
  });
25211
25268
  if (opts.path) {
25212
- yield import_fs6.promises.writeFile(opts.path, buffer);
25269
+ yield import_fs7.promises.writeFile(opts.path, buffer);
25213
25270
  }
25214
25271
  return buffer;
25215
25272
  } finally {
@@ -61799,7 +61856,6 @@ var AISdkClient2 = class extends LLMClient {
61799
61856
  };
61800
61857
 
61801
61858
  // lib/v3/understudy/context.ts
61802
- var import_fs7 = require("fs");
61803
61859
  init_logger();
61804
61860
 
61805
61861
  // lib/v3/understudy/cdp.ts
@@ -62075,43 +62131,8 @@ function installV3PiercerIntoSession(session) {
62075
62131
 
62076
62132
  // lib/v3/understudy/context.ts
62077
62133
  init_executionContextRegistry();
62134
+ init_initScripts();
62078
62135
  init_sdkErrors();
62079
- function normalizeInitScriptSource(script, arg) {
62080
- return __async(this, null, function* () {
62081
- if (typeof script === "function") {
62082
- const argString = Object.is(arg, void 0) ? "undefined" : JSON.stringify(arg);
62083
- return `(${script.toString()})(${argString})`;
62084
- }
62085
- if (!Object.is(arg, void 0)) {
62086
- throw new StagehandInvalidArgumentError(
62087
- "context.addInitScript: 'arg' is only supported when passing a function."
62088
- );
62089
- }
62090
- if (typeof script === "string") {
62091
- return script;
62092
- }
62093
- if (!script || typeof script !== "object") {
62094
- throw new StagehandInvalidArgumentError(
62095
- "context.addInitScript: provide a string, function, or an object with path/content."
62096
- );
62097
- }
62098
- if (typeof script.content === "string") {
62099
- return script.content;
62100
- }
62101
- if (typeof script.path === "string" && script.path.trim()) {
62102
- const raw = yield import_fs7.promises.readFile(script.path, "utf8");
62103
- return appendSourceURL(raw, script.path);
62104
- }
62105
- throw new StagehandInvalidArgumentError(
62106
- "context.addInitScript: provide a string, function, or an object with path/content."
62107
- );
62108
- });
62109
- }
62110
- function appendSourceURL(source, filePath) {
62111
- const sanitized = filePath.replace(/\n/g, "");
62112
- return `${source}
62113
- //# sourceURL=${sanitized}`;
62114
- }
62115
62136
  function isTopLevelPage(info) {
62116
62137
  const ti = info;
62117
62138
  return info.type === "page" && ti.subtype !== "iframe";
@@ -62407,6 +62428,7 @@ var V3Context = class _V3Context {
62407
62428
  yield this.conn.enableAutoAttach();
62408
62429
  const targets = yield this.conn.getTargets();
62409
62430
  for (const t2 of targets) {
62431
+ if (t2.attached) continue;
62410
62432
  try {
62411
62433
  yield this.conn.attachToTarget(t2.targetId);
62412
62434
  } catch (e2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "3.0.6-alpha-45bcef0e5788b083f9e38dfd7c3bc63afcd4b6dd",
3
+ "version": "3.0.6-alpha-bb85ad912738623a7a866f0cb6e8d5807c6c2738",
4
4
  "description": "An AI web browsing framework focused on simplicity and extensibility.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",