@browserbasehq/stagehand 3.1.0-alpha-7e72adfd7e4af5ec49ac2f552e7f1f57c1acc554 → 3.1.0-alpha-5556041e2deaed5012363303fd7a8ac00e3242cd

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
@@ -199,11 +199,7 @@ declare class CdpConnection implements CDPSessionLike {
199
199
  close(): Promise<void>;
200
200
  getSession(sessionId: string): CdpSession | undefined;
201
201
  attachToTarget(targetId: string): Promise<CdpSession>;
202
- getTargets(): Promise<Array<{
203
- targetId: string;
204
- type: string;
205
- url: string;
206
- }>>;
202
+ getTargets(): Promise<Protocol.Target.TargetInfo[]>;
207
203
  private onMessage;
208
204
  _sendViaSession<R = unknown>(sessionId: string, method: string, params?: object): Promise<R>;
209
205
  _onSessionEvent(sessionId: string, event: string, handler: EventHandler): void;
@@ -1711,6 +1707,7 @@ declare class V3Context {
1711
1707
  * We poll internal maps that bootstrap/onAttachedToTarget populate.
1712
1708
  */
1713
1709
  private waitForFirstTopLevelPage;
1710
+ private waitForInitialTopLevelTargets;
1714
1711
  private ensurePiercer;
1715
1712
  /** Mark a page target as the most-recent one (active). */
1716
1713
  private _pushActive;
package/dist/index.js CHANGED
@@ -85,7 +85,7 @@ var __async = (__this, __arguments, generator) => {
85
85
  var STAGEHAND_VERSION;
86
86
  var init_version = __esm({
87
87
  "lib/version.ts"() {
88
- STAGEHAND_VERSION = "3.1.0-alpha-7e72adfd7e4af5ec49ac2f552e7f1f57c1acc554";
88
+ STAGEHAND_VERSION = "3.1.0-alpha-5556041e2deaed5012363303fd7a8ac00e3242cd";
89
89
  }
90
90
  });
91
91
 
@@ -39112,7 +39112,6 @@ var V3Context = class _V3Context {
39112
39112
  return __async(this, null, function* () {
39113
39113
  var _a, _b, _c;
39114
39114
  const conn = yield CdpConnection.connect(wsUrl);
39115
- yield conn.enableAutoAttach();
39116
39115
  const ctx = new _V3Context(
39117
39116
  conn,
39118
39117
  (_a = opts == null ? void 0 : opts.env) != null ? _a : "LOCAL",
@@ -39146,6 +39145,35 @@ var V3Context = class _V3Context {
39146
39145
  );
39147
39146
  });
39148
39147
  }
39148
+ waitForInitialTopLevelTargets(targetIds, timeoutMs = 3e3) {
39149
+ return __async(this, null, function* () {
39150
+ if (!targetIds.length) return;
39151
+ const pending = new Set(targetIds);
39152
+ const deadline = Date.now() + timeoutMs;
39153
+ while (pending.size && Date.now() < deadline) {
39154
+ for (const tid of Array.from(pending)) {
39155
+ if (this.pagesByTarget.has(tid)) {
39156
+ pending.delete(tid);
39157
+ }
39158
+ }
39159
+ if (!pending.size) return;
39160
+ yield new Promise((r) => setTimeout(r, 25));
39161
+ }
39162
+ if (pending.size) {
39163
+ v3Logger({
39164
+ category: "ctx",
39165
+ message: "Timed out waiting for existing top-level targets to attach",
39166
+ level: 2,
39167
+ auxiliary: {
39168
+ remainingTargets: {
39169
+ value: JSON.stringify(Array.from(pending)),
39170
+ type: "object"
39171
+ }
39172
+ }
39173
+ });
39174
+ }
39175
+ });
39176
+ }
39149
39177
  ensurePiercer(session) {
39150
39178
  return __async(this, null, function* () {
39151
39179
  const key = this.sessionKey(session);
@@ -39326,6 +39354,7 @@ var V3Context = class _V3Context {
39326
39354
  }
39327
39355
  })
39328
39356
  );
39357
+ yield this.conn.enableAutoAttach();
39329
39358
  const targets = yield this.conn.getTargets();
39330
39359
  for (const t of targets) {
39331
39360
  try {
@@ -39333,6 +39362,8 @@ var V3Context = class _V3Context {
39333
39362
  } catch (e) {
39334
39363
  }
39335
39364
  }
39365
+ const topLevelTargetIds = targets.filter((t) => isTopLevelPage(t)).map((t) => t.targetId);
39366
+ yield this.waitForInitialTopLevelTargets(topLevelTargetIds);
39336
39367
  });
39337
39368
  }
39338
39369
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@browserbasehq/stagehand",
3
- "version": "3.1.0-alpha-7e72adfd7e4af5ec49ac2f552e7f1f57c1acc554",
3
+ "version": "3.1.0-alpha-5556041e2deaed5012363303fd7a8ac00e3242cd",
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",