Skip to content

Commit cfe5445

Browse files
Add initBrowser listener getter trap regression
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent dd20c76 commit cfe5445

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎currentState.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ HyperAgent exposes a TypeScript SDK for browser automation with three primary pa
203203
- Hardened Playwright session listener wrappers:
204204
- `PlaywrightSessionAdapter.on()` and `.off()` now guard trap-prone listener method reads and wrap listener registration/removal failures with sanitized diagnostics.
205205
- Added adapter regressions for trap-prone `session.on`/`session.off` getter diagnostics to lock the listener-wrapper hardening behavior.
206+
- Added initBrowser regression coverage for trap-prone browser-context listener getters:
207+
- debug mode now asserts deterministic "context.on is unavailable" diagnostics when context listener methods cannot be read during browser initialization.
206208
- Hardened A11y DOM option ingestion (`useCache`, `onFrameChunk`, `filterAdTrackingFrames`) with trap-safe reads, so malformed option objects no longer break extraction setup.
207209
- Hardened A11y DOM debug-option lookup (`getDebugOptions`) with trap-safe fallback defaults and sanitized warning diagnostics.
208210
- Hardened OpenAI/Anthropic structured-schema debug-option reads so trap-prone debug-option access no longer interrupts structured invocation paths.

‎src/agent/__tests__/hyperagent-constructor.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,49 @@ describe("HyperAgent constructor and task controls", () => {
19221922
}
19231923
});
19241924

1925+
it("initBrowser logs unavailable context page-listener methods in debug mode", async () => {
1926+
const warnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
1927+
const context = new Proxy(
1928+
{},
1929+
{
1930+
get: (_target, prop) => {
1931+
if (prop === "on") {
1932+
throw new Error("context.on getter trap");
1933+
}
1934+
return undefined;
1935+
},
1936+
}
1937+
) as unknown as { on: () => void };
1938+
const browser = {
1939+
newContext: async () => context,
1940+
};
1941+
const agent = new HyperAgent({
1942+
llm: createMockLLM(),
1943+
debug: true,
1944+
});
1945+
const internalAgent = agent as unknown as {
1946+
browserProvider: {
1947+
start: () => Promise<unknown>;
1948+
close: () => Promise<void>;
1949+
getSession: () => unknown;
1950+
};
1951+
};
1952+
internalAgent.browserProvider = {
1953+
start: async () => browser,
1954+
close: async () => undefined,
1955+
getSession: () => ({ id: "session-1" }),
1956+
};
1957+
1958+
try {
1959+
await expect(agent.initBrowser()).resolves.toBe(browser);
1960+
expect(warnSpy).toHaveBeenCalledWith(
1961+
"[HyperAgent] Failed to attach browser page listener: context.on is unavailable"
1962+
);
1963+
} finally {
1964+
warnSpy.mockRestore();
1965+
}
1966+
});
1967+
19251968
it("initBrowser aborts stale provider starts after closeAgent generation changes", async () => {
19261969
const close = jest.fn(async () => undefined);
19271970
let resolveStart!: (browser: unknown) => void;

0 commit comments

Comments
 (0)