Skip to content

Commit 28bb1dd

Browse files
Normalize replay waitForLoadState targets
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent db91e5d commit 28bb1dd

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/agent/shared/replay-special-actions.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ describe("executeReplaySpecialAction", () => {
163163
expect(result?.output).toBe("Waited for load state: networkidle");
164164
});
165165

166+
it("defaults waitForLoadState to domcontentloaded for unsupported values", async () => {
167+
const page = createPage();
168+
169+
const result = await executeReplaySpecialAction({
170+
taskId: "task-loadstate-invalid",
171+
actionType: "waitForLoadState",
172+
arguments: ["interactive"],
173+
page: page as unknown as Page,
174+
});
175+
176+
expect(page.waitForLoadState).toHaveBeenCalledWith("domcontentloaded", undefined);
177+
expect(result?.status).toBe("completed");
178+
expect(result?.output).toBe("Waited for load state: domcontentloaded");
179+
});
180+
166181
it("fails extract replay when extracted object cannot be serialized", async () => {
167182
const circular: Record<string, unknown> = {};
168183
circular.self = circular;

src/agent/shared/replay-special-actions.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ function normalizeWaitMs(value: unknown): number {
6868
return parsed >= 0 ? parsed : 1000;
6969
}
7070

71+
function normalizeWaitUntil(value: unknown): "domcontentloaded" | "load" | "networkidle" {
72+
const parsed = asNonEmptyTrimmedString(value);
73+
if (parsed === "load" || parsed === "networkidle") {
74+
return parsed;
75+
}
76+
return "domcontentloaded";
77+
}
78+
7179
export async function executeReplaySpecialAction(
7280
params: ReplaySpecialActionInput
7381
): Promise<TaskOutput | null> {
@@ -215,12 +223,12 @@ export async function executeReplaySpecialAction(
215223
}
216224

217225
if (actionType === "waitForLoadState") {
218-
const waitUntil = asNonEmptyTrimmedString(actionArgs?.[0]) ?? "domcontentloaded";
226+
const waitUntil = normalizeWaitUntil(actionArgs?.[0]);
219227
const timeoutMs = asFiniteNumber(actionArgs?.[1]);
220228
const options =
221229
timeoutMs !== undefined ? { timeout: timeoutMs } : undefined;
222230
await page.waitForLoadState(
223-
waitUntil as "domcontentloaded" | "load" | "networkidle",
231+
waitUntil,
224232
options
225233
);
226234
markDomSnapshotDirty(page);

0 commit comments

Comments
 (0)