Skip to content
Open
Show file tree
Hide file tree
Changes from all 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/fix-piercer-debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

fix(core): respect v3 piercer debug option
3 changes: 1 addition & 2 deletions packages/core/lib/v3/dom/piercer.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ declare global {
}

export function installV3ShadowPiercer(opts: V3ShadowPatchOptions = {}): void {
// hardcoded debug (remove later if desired)
const DEBUG = true;
const DEBUG = opts.debug ?? false;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Stop enabling piercer debug in the injected entry

Changing this default does not silence the runtime path used by normal V3 sessions: scripts/build-dom-scripts.ts bundles lib/v3/dom/piercer.entry.ts into v3ScriptContent, understudy/piercer.ts injects/evaluates that script, and the entry still calls installV3ShadowPiercer({ debug: true, tagExisting: false }). In those sessions the new default is bypassed, so [v3-piercer] console logs continue even when debug is not requested; the added unit test only covers direct calls to installV3ShadowPiercer().

Useful? React with 👍 / 👎.


type PatchedFn = Element["attachShadow"] & {
__v3Patched?: boolean;
Expand Down
49 changes: 49 additions & 0 deletions packages/core/tests/unit/v3-piercer-debug.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { afterEach, describe, expect, it, vi } from "vitest";

import { installV3ShadowPiercer } from "../../lib/v3/dom/piercer.runtime";

class TestElement {
tagName = "TEST-ELEMENT";

attachShadow(_init: ShadowRootInit): ShadowRoot {
return {} as ShadowRoot;
}
}

function installDomGlobals() {
vi.stubGlobal("Element", TestElement);
vi.stubGlobal("location", { href: "https://example.com" });
vi.stubGlobal("window", {
top: undefined,
__stagehandV3Injected: undefined,
__stagehandV3__: undefined,
});
window.top = window;
}

describe("installV3ShadowPiercer debug logging", () => {
afterEach(() => {
vi.unstubAllGlobals();
vi.restoreAllMocks();
});

it("does not log by default", () => {
installDomGlobals();
const info = vi.spyOn(console, "info").mockImplementation(() => {});

installV3ShadowPiercer();
new TestElement().attachShadow({ mode: "closed" });

expect(info).not.toHaveBeenCalled();
});

it("logs when debug is enabled", () => {
installDomGlobals();
const info = vi.spyOn(console, "info").mockImplementation(() => {});

installV3ShadowPiercer({ debug: true });
new TestElement().attachShadow({ mode: "closed" });

expect(info).toHaveBeenCalled();
});
});
Loading