Skip to content

Commit fea2b4e

Browse files
Propagate record-video trace mode into network settle diagnostics
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 1440fe5 commit fea2b4e

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

‎currentState.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ HyperAgent exposes a TypeScript SDK for browser automation with three primary pa
149149
- Hardened `waitForSettledDOM` option reads for frame filtering with trap-safe accessors, so malformed/trap-prone option objects no longer break settle flow or frame-manager configuration.
150150
- Hardened wait-listener lifecycle cleanup against trap-prone session listener-method getters, preserving settle completion while emitting sanitized detach diagnostics.
151151
- Expanded settle-flow listener regressions to cover trap-prone `session.on` getters, ensuring timeout-based fallback remains deterministic under unreadable listener APIs.
152+
- Aligned settle network-tracing behavior so recording-video sessions now propagate trace mode into network-idle diagnostics (including stalled-request warnings) even when debug flags are off.
152153
- Hardened constructor LLM validation to reject malformed non-provider/non-client `llm` payloads instead of accepting invalid runtime objects, while preserving trap-safe config reads.
153154
- Added explicit constructor regression coverage for malformed partial `llm` objects to lock in fail-fast configuration behavior.
154155
- Hardened prompt final-goal rendering against malformed/trap-prone task inputs by normalizing non-string goals into bounded readable diagnostics instead of throwing.

‎src/utils/waitForSettledDOM.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,59 @@ describe("waitForSettledDOM diagnostics", () => {
252252
expect(setFrameFilteringEnabled).toHaveBeenCalledWith(false);
253253
});
254254

255+
it("enables network trace diagnostics when context is recording video", async () => {
256+
const warnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
257+
const { session, emit } = createSessionWithEvents();
258+
const cdpClient: CDPClient = {
259+
rootSession: session,
260+
createSession: async () => session,
261+
acquireSession: async () => session,
262+
dispose: async () => undefined,
263+
};
264+
getCDPClient.mockResolvedValue(cdpClient);
265+
getOrCreateFrameContextManager.mockReturnValue({
266+
setDebug: jest.fn(),
267+
});
268+
getDebugOptions.mockReturnValue({
269+
enabled: false,
270+
traceWait: false,
271+
});
272+
273+
const page = {
274+
context: () => ({
275+
_options: {
276+
recordVideo: {},
277+
},
278+
}),
279+
} as never;
280+
281+
try {
282+
const waitPromise = waitForSettledDOM(page, 5_000);
283+
await Promise.resolve();
284+
await Promise.resolve();
285+
286+
emit("Network.requestWillBeSent", {
287+
requestId: "req-1",
288+
type: "Document",
289+
request: { url: "https://example.com/video" },
290+
});
291+
292+
await jest.advanceTimersByTimeAsync(3_100);
293+
await waitPromise;
294+
295+
const traceMessages = warnSpy.mock.calls
296+
.map((call) => String(call[0] ?? ""))
297+
.filter((message) => message.includes("[waitForSettledDOM]"));
298+
expect(
299+
traceMessages.some((message) =>
300+
message.includes("Forcing completion of stalled request")
301+
)
302+
).toBe(true);
303+
} finally {
304+
warnSpy.mockRestore();
305+
}
306+
});
307+
255308
it("continues when frame-filter configuration throws", async () => {
256309
const warnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
257310
const { session } = createSessionWithEvents();

‎src/utils/waitForSettledDOM.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export async function waitForSettledDOM(
265265
const networkStart = performance.now();
266266
const stats = await waitForNetworkIdle(lifecycleSession, {
267267
timeoutMs: normalizedTimeoutMs,
268-
trace: traceWaitFlag,
268+
trace: traceWait,
269269
});
270270
const networkDuration = performance.now() - networkStart;
271271

0 commit comments

Comments
 (0)