Repository: browserbase/stagehand
File: lib/StagehandPage.ts (TypeScript)

Code before:
    const sessionStatus = await browserbase.sessions.retrieve(sessionId);
    const browserbaseDomain =
      BROWSERBASE_REGION_DOMAIN[sessionStatus.region] ||
      "wss://connect.browserbase.com";
    const connectUrl = `${browserbaseDomain}?apiKey=${process.env.BROWSERBASE_API_KEY}&sessionId=${sessionId}`;

    const browser = await chromium.connectOverCDP(connectUrl);
    const context = browser.contexts()[0];
    const newPage = context.pages()[0];

    const newStagehandPage = await new StagehandPage(
      newPage,
      this.stagehand,
      this.intContext,
      this.llmClient,
      this.userProvidedInstructions,
      this.api,
    ).init();

    this.intPage = newStagehandPage.page;

    if (this.stagehand.debugDom) {
      this.stagehand.log({
        category: "deprecation",
        message:
          "Warning: vision is not supported in this version of Stagehand",
        level: 1,
      });
    }
    await this.intPage.waitForLoadState("domcontentloaded");
    await this._waitForSettledDom();
  }

  /**
   * Waits for a captcha to be solved when using Browserbase environment.
   *
   * @param timeoutMs - Optional timeout in milliseconds. If provided, the promise will reject if the captcha solving hasn't started within the given time.
   * @throws Error if called in a LOCAL environment
   * @throws Error if the timeout is reached before captcha solving starts
   * @returns Promise that resolves when the captcha is solved
   */
  public async waitForCaptchaSolve(timeoutMs?: number) {
    if (this.stagehand.env === "LOCAL") {
      throw new Error(
        "The waitForCaptcha method may only be used when using the Browserbase environment.",
      );
    }

    this.stagehand.log({
      category: "captcha",
      message: "Waiting for captcha",

Review comment (bug):
```suggestion
          "Warning: debugDom is not supported in this version of Stagehand",
```

Code after:
    const sessionStatus = await browserbase.sessions.retrieve(sessionId);
    const browserbaseDomain =
      BROWSERBASE_REGION_DOMAIN[sessionStatus.region] ||
      "wss://connect.browserbase.com";
    const connectUrl = `${browserbaseDomain}?apiKey=${process.env.BROWSERBASE_API_KEY}&sessionId=${sessionId}`;

    const browser = await chromium.connectOverCDP(connectUrl);
    const context = browser.contexts()[0];
    const newPage = context.pages()[0];

    const newStagehandPage = await new StagehandPage(
      newPage,
      this.stagehand,
      this.intContext,
      this.llmClient,
      this.userProvidedInstructions,
      this.api,
    ).init();

    this.intPage = newStagehandPage.page;

    if (this.stagehand.debugDom) {
      this.stagehand.log({
        category: "deprecation",
        message:
          "Warning: debugDom is not supported in this version of Stagehand",
        level: 1,
      });
    }
    await this.intPage.waitForLoadState("domcontentloaded");
    await this._waitForSettledDom();
  }

  /**
   * Waits for a captcha to be solved when using Browserbase environment.
   *
   * @param timeoutMs - Optional timeout in milliseconds. If provided, the promise will reject if the captcha solving hasn't started within the given time.
   * @throws Error if called in a LOCAL environment
   * @throws Error if the timeout is reached before captcha solving starts
   * @returns Promise that resolves when the captcha is solved
   */
  public async waitForCaptchaSolve(timeoutMs?: number) {
    if (this.stagehand.env === "LOCAL") {
      throw new Error(
        "The waitForCaptcha method may only be used when using the Browserbase environment.",
      );
    }

    this.stagehand.log({
      category: "captcha",
      message: "Waiting for captcha",