Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shiny-windows-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

remove debugDom
62 changes: 12 additions & 50 deletions lib/StagehandPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ export class StagehandPage {
this.intPage = newStagehandPage.page;

if (this.stagehand.debugDom) {
await this.intPage.evaluate(
(debugDom) => (window.showChunks = debugDom),
this.stagehand.debugDom,
);
this.stagehand.log({
category: "deprecation",
message:
"Warning: vision is not supported in this version of Stagehand",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Warning: vision is not supported in this version of Stagehand",
"Warning: debugDom is not supported in this version of Stagehand",

level: 1,
});
}
await this.intPage.waitForLoadState("domcontentloaded");
await this._waitForSettledDom();
Expand Down Expand Up @@ -268,10 +270,12 @@ export class StagehandPage {
await this._refreshPageFromAPI();
} else {
if (stagehand.debugDom) {
await target.evaluate(
(debugDom) => (window.showChunks = debugDom),
stagehand.debugDom,
);
this.stagehand.log({
category: "deprecation",
message:
"Warning: debugDom is not supported in this version of Stagehand",
level: 1,
});
}
await target.waitForLoadState("domcontentloaded");
await this._waitForSettledDom();
Expand Down Expand Up @@ -400,48 +404,6 @@ export class StagehandPage {
}
}

public async startDomDebug() {
if (this.stagehand.debugDom) {
try {
await this.page
.evaluate(() => {
if (typeof window.debugDom === "function") {
window.debugDom();
} else {
this.stagehand.log({
category: "dom",
message: "debugDom is not defined",
level: 1,
});
}
})
.catch(() => {});
} catch (e) {
this.stagehand.log({
category: "dom",
message: "Error in startDomDebug",
level: 1,
auxiliary: {
error: {
value: e.message,
type: "string",
},
trace: {
value: e.stack,
type: "string",
},
},
});
}
}
}

public async cleanupDomDebug() {
if (this.stagehand.debugDom) {
await this.page.evaluate(() => window.cleanupDebug()).catch(() => {});
}
}

async act(
actionOrOptions: string | ActOptions | ObserveResult,
): Promise<ActResult> {
Expand Down
101 changes: 0 additions & 101 deletions lib/dom/debug.ts

This file was deleted.

2 changes: 0 additions & 2 deletions lib/dom/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ declare global {
outputString: string;
selectorMap: Record<number, string[]>;
}>;
debugDom: () => Promise<void>;
cleanupDebug: () => void;
createStagehandContainer: (obj: Window | HTMLElement) => StagehandContainer;
waitForDomSettle: () => Promise<void>;
__playwright?: unknown;
Expand Down
1 change: 0 additions & 1 deletion lib/dom/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./process";
export * from "./utils";
export * from "./debug";
3 changes: 0 additions & 3 deletions lib/handlers/actHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ export class StagehandActHandler {
}): Promise<{ success: boolean; message: string; action: string }> {
try {
await this.stagehandPage._waitForSettledDom(domSettleTimeoutMs);
await this.stagehandPage.startDomDebug();

if (timeoutMs && startTime) {
const elapsedTime = Date.now() - startTime;
Expand Down Expand Up @@ -916,8 +915,6 @@ export class StagehandActHandler {
},
});

await this.stagehandPage.cleanupDomDebug();

if (!response) {
if (chunksSeen.length + 1 < chunks.length) {
chunksSeen.push(chunk);
Expand Down
10 changes: 0 additions & 10 deletions lib/handlers/extractHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export class StagehandExtractHandler {

private async extractPageText(): Promise<{ page_text?: string }> {
await this.stagehandPage._waitForSettledDom();
await this.stagehandPage.startDomDebug();

const originalDOM = await this.stagehandPage.page.evaluate(() =>
window.storeDOM(undefined),
Expand Down Expand Up @@ -202,8 +201,6 @@ export class StagehandExtractHandler {
containerDims.width,
);

await this.stagehandPage.cleanupDomDebug();

const result = { page_text: formattedText };
return pageTextSchema.parse(result);
}
Expand Down Expand Up @@ -239,7 +236,6 @@ export class StagehandExtractHandler {

// **1:** Wait for the DOM to settle and start DOM debugging
await this.stagehandPage._waitForSettledDom(domSettleTimeoutMs);
await this.stagehandPage.startDomDebug();

const targetXpath = selector?.replace(/^xpath=/, "") ?? "";

Expand Down Expand Up @@ -364,9 +360,6 @@ export class StagehandExtractHandler {
...output
} = extractionResponse;

// Clean up debug
await this.stagehandPage.cleanupDomDebug();

// **11:** Handle the extraction response and log the results
this.logger({
category: "extraction",
Expand Down Expand Up @@ -439,7 +432,6 @@ export class StagehandExtractHandler {
// **1:** Wait for the DOM to settle and start DOM debugging
// This ensures the page is stable before extracting any data.
await this.stagehandPage._waitForSettledDom(domSettleTimeoutMs);
await this.stagehandPage.startDomDebug();

// **2:** Call processDom() to handle chunk-based extraction
// processDom determines which chunk of the page to process next.
Expand Down Expand Up @@ -496,8 +488,6 @@ export class StagehandExtractHandler {
...output
} = extractionResponse;

await this.stagehandPage.cleanupDomDebug();

this.logger({
category: "extraction",
message: "received extraction response",
Expand Down
1 change: 0 additions & 1 deletion lib/handlers/observeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ export class StagehandObserveHandler {
};
}),
);
await this.stagehandPage.cleanupDomDebug();

this.logger({
category: "observation",
Expand Down
1 change: 1 addition & 0 deletions types/stagehand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface ConstructorParams {
apiKey?: string;
projectId?: string;
verbose?: 0 | 1 | 2;
/** @deprecated Dom Debugging is no longer supported in this version of Stagehand. */
debugDom?: boolean;
llmProvider?: LLMProvider;
/** @deprecated Please use `localBrowserLaunchOptions` instead. That will override this. */
Expand Down