Skip to content

Conversation

miguelg719
Copy link
Collaborator

No description provided.

Copy link

vercel bot commented Sep 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
priv-gemini-browser Ready Ready Preview Comment Oct 6, 2025 9:27pm

Copy link

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments:

sdk/stagehand-ts/lib/index.ts (line 875):

The close() method will throw an error if called before init() or if init() fails, because it tries to access this.context which requires stagehandContext to be initialized.

View Details
📝 Patch Details
diff --git a/sdk/stagehand-ts/dist/index.js b/sdk/stagehand-ts/dist/index.js
index ff6c1d6..e3da4b6 100644
--- a/sdk/stagehand-ts/dist/index.js
+++ b/sdk/stagehand-ts/dist/index.js
@@ -23726,7 +23726,9 @@ var Stagehand3 = class {
         this.apiClient = null;
         return;
       } else {
-        yield this.context.close();
+        if (this.stagehandContext) {
+          yield this.context.close();
+        }
         if (this._browser) {
           yield this._browser.close();
         }
diff --git a/sdk/stagehand-ts/lib/index.ts b/sdk/stagehand-ts/lib/index.ts
index e158322..88c75ac 100644
--- a/sdk/stagehand-ts/lib/index.ts
+++ b/sdk/stagehand-ts/lib/index.ts
@@ -872,7 +872,9 @@ export class Stagehand {
       this.apiClient = null;
       return;
     } else {
-      await this.context.close();
+      if (this.stagehandContext) {
+        await this.context.close();
+      }
       if (this._browser) {
         await this._browser.close();
       }

Analysis

close() method fails when called before init() due to unguarded context access

What fails: Stagehand.close() throws StagehandNotInitializedError when called before init() because it unconditionally calls this.context.close() which requires stagehandContext to be initialized

How to reproduce:

const stagehand = new Stagehand({ env: "LOCAL" });
await stagehand.close(); // Throws StagehandNotInitializedError

Result: Throws "You seem to be calling context on a page in an uninitialized Stagehand object. Ensure you are running await stagehand.init() on the Stagehand object before referencing the page object."

Expected: close() should handle uninitialized state gracefully, especially since signal handlers (SIGINT/SIGTERM) registered in constructor call close() for cleanup - if process is interrupted before init() completes, cleanup fails instead of gracefully handling uninitialized state.

Technical details: The context getter at lines 735-739 in lib/index.ts throws when this.stagehandContext is undefined, but close() method at line 875 calls await this.context.close() without checking initialization state.

* update urls, ts ignore fix (#8)

* feat: add query param parsing (#9)

* update urls, ts ignore fix

* added query param parsing to instatiate chatfeed with query params

* disable captcha solving if query params are passed in (#10)

* update gemini model

* update model tag (#12)

* add region routing

* more precise region & probability dist routing

* no inline import

* add dep

---------

Co-authored-by: Kyle Jeong <77771518+Kylejeong2@users.noreply.github.com>
Co-authored-by: Miguel <36487034+miguelg719@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants