Skip to content

Commit 4fdbf63

Browse files
get rid of domDebug (#577)
* get rid of domDebug * changeset * fix log message
1 parent 179e17c commit 4fdbf63

File tree

9 files changed

+18
-168
lines changed

9 files changed

+18
-168
lines changed

Diff for: .changeset/shiny-windows-attack.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
remove debugDom

Diff for: lib/StagehandPage.ts

+12-50
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ export class StagehandPage {
149149
this.intPage = newStagehandPage.page;
150150

151151
if (this.stagehand.debugDom) {
152-
await this.intPage.evaluate(
153-
(debugDom) => (window.showChunks = debugDom),
154-
this.stagehand.debugDom,
155-
);
152+
this.stagehand.log({
153+
category: "deprecation",
154+
message:
155+
"Warning: debugDom is not supported in this version of Stagehand",
156+
level: 1,
157+
});
156158
}
157159
await this.intPage.waitForLoadState("domcontentloaded");
158160
await this._waitForSettledDom();
@@ -268,10 +270,12 @@ export class StagehandPage {
268270
await this._refreshPageFromAPI();
269271
} else {
270272
if (stagehand.debugDom) {
271-
await target.evaluate(
272-
(debugDom) => (window.showChunks = debugDom),
273-
stagehand.debugDom,
274-
);
273+
this.stagehand.log({
274+
category: "deprecation",
275+
message:
276+
"Warning: debugDom is not supported in this version of Stagehand",
277+
level: 1,
278+
});
275279
}
276280
await target.waitForLoadState("domcontentloaded");
277281
await this._waitForSettledDom();
@@ -400,48 +404,6 @@ export class StagehandPage {
400404
}
401405
}
402406

403-
public async startDomDebug() {
404-
if (this.stagehand.debugDom) {
405-
try {
406-
await this.page
407-
.evaluate(() => {
408-
if (typeof window.debugDom === "function") {
409-
window.debugDom();
410-
} else {
411-
this.stagehand.log({
412-
category: "dom",
413-
message: "debugDom is not defined",
414-
level: 1,
415-
});
416-
}
417-
})
418-
.catch(() => {});
419-
} catch (e) {
420-
this.stagehand.log({
421-
category: "dom",
422-
message: "Error in startDomDebug",
423-
level: 1,
424-
auxiliary: {
425-
error: {
426-
value: e.message,
427-
type: "string",
428-
},
429-
trace: {
430-
value: e.stack,
431-
type: "string",
432-
},
433-
},
434-
});
435-
}
436-
}
437-
}
438-
439-
public async cleanupDomDebug() {
440-
if (this.stagehand.debugDom) {
441-
await this.page.evaluate(() => window.cleanupDebug()).catch(() => {});
442-
}
443-
}
444-
445407
async act(
446408
actionOrOptions: string | ActOptions | ObserveResult,
447409
): Promise<ActResult> {

Diff for: lib/dom/debug.ts

-101
This file was deleted.

Diff for: lib/dom/global.d.ts

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ declare global {
1515
outputString: string;
1616
selectorMap: Record<number, string[]>;
1717
}>;
18-
debugDom: () => Promise<void>;
19-
cleanupDebug: () => void;
2018
createStagehandContainer: (obj: Window | HTMLElement) => StagehandContainer;
2119
waitForDomSettle: () => Promise<void>;
2220
__playwright?: unknown;

Diff for: lib/dom/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from "./process";
22
export * from "./utils";
3-
export * from "./debug";

Diff for: lib/handlers/actHandler.ts

-3
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,6 @@ export class StagehandActHandler {
605605
}): Promise<{ success: boolean; message: string; action: string }> {
606606
try {
607607
await this.stagehandPage._waitForSettledDom(domSettleTimeoutMs);
608-
await this.stagehandPage.startDomDebug();
609608

610609
if (timeoutMs && startTime) {
611610
const elapsedTime = Date.now() - startTime;
@@ -696,8 +695,6 @@ export class StagehandActHandler {
696695
},
697696
});
698697

699-
await this.stagehandPage.cleanupDomDebug();
700-
701698
if (!response) {
702699
if (chunksSeen.length + 1 < chunks.length) {
703700
chunksSeen.push(chunk);

Diff for: lib/handlers/extractHandler.ts

-10
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ export class StagehandExtractHandler {
164164

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

169168
const originalDOM = await this.stagehandPage.page.evaluate(() =>
170169
window.storeDOM(undefined),
@@ -202,8 +201,6 @@ export class StagehandExtractHandler {
202201
containerDims.width,
203202
);
204203

205-
await this.stagehandPage.cleanupDomDebug();
206-
207204
const result = { page_text: formattedText };
208205
return pageTextSchema.parse(result);
209206
}
@@ -239,7 +236,6 @@ export class StagehandExtractHandler {
239236

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

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

@@ -364,9 +360,6 @@ export class StagehandExtractHandler {
364360
...output
365361
} = extractionResponse;
366362

367-
// Clean up debug
368-
await this.stagehandPage.cleanupDomDebug();
369-
370363
// **11:** Handle the extraction response and log the results
371364
this.logger({
372365
category: "extraction",
@@ -439,7 +432,6 @@ export class StagehandExtractHandler {
439432
// **1:** Wait for the DOM to settle and start DOM debugging
440433
// This ensures the page is stable before extracting any data.
441434
await this.stagehandPage._waitForSettledDom(domSettleTimeoutMs);
442-
await this.stagehandPage.startDomDebug();
443435

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

499-
await this.stagehandPage.cleanupDomDebug();
500-
501491
this.logger({
502492
category: "extraction",
503493
message: "received extraction response",

Diff for: lib/handlers/observeHandler.ts

-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ export class StagehandObserveHandler {
185185
};
186186
}),
187187
);
188-
await this.stagehandPage.cleanupDomDebug();
189188

190189
this.logger({
191190
category: "observation",

Diff for: types/stagehand.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface ConstructorParams {
1313
apiKey?: string;
1414
projectId?: string;
1515
verbose?: 0 | 1 | 2;
16+
/** @deprecated Dom Debugging is no longer supported in this version of Stagehand. */
1617
debugDom?: boolean;
1718
llmProvider?: LLMProvider;
1819
/** @deprecated Please use `localBrowserLaunchOptions` instead. That will override this. */

0 commit comments

Comments
 (0)