Skip to content

Commit 647eefd

Browse files
authored
fix debugDom parameter (#227)
1 parent 4bebe20 commit 647eefd

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

.changeset/olive-trains-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Fix debugDom still showing chunks when set to false

lib/dom/debug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function multiSelectorMapToSelectorMap(
2222
}
2323

2424
function drawChunk(selectorMap: Record<number, string>) {
25+
if (!window.showChunks) return;
2526
cleanupMarkers();
2627
Object.entries(selectorMap).forEach(([_index, selector]) => {
2728
const element = document.evaluate(

lib/dom/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export {};
22
declare global {
33
interface Window {
44
chunkNumber: number;
5+
showChunks?: boolean;
56
processDom: (chunksSeen: Array<number>) => Promise<{
67
outputString: string;
78
selectorMap: Record<number, string[]>;

lib/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ export class Stagehand {
390390
const originalGoto = this.page.goto.bind(this.page);
391391
this.page.goto = async (url: string, options?: any) => {
392392
const result = await originalGoto(url, options);
393+
if (this.debugDom) {
394+
await this.page.evaluate(() => (window.showChunks = this.debugDom));
395+
}
393396
await this.page.waitForLoadState("domcontentloaded");
394397
await this._waitForSettledDom();
395398
return result;
@@ -456,6 +459,9 @@ export class Stagehand {
456459
const originalGoto = this.page.goto.bind(this.page);
457460
this.page.goto = async (url: string, options?: any) => {
458461
const result = await originalGoto(url, options);
462+
if (this.debugDom) {
463+
await this.page.evaluate(() => (window.showChunks = this.debugDom));
464+
}
459465
await this.page.waitForLoadState("domcontentloaded");
460466
await this._waitForSettledDom();
461467
return result;

0 commit comments

Comments
 (0)