fix(browser): distinguish duplicate screenshot frame events (#612)

* fix(browser): distinguish duplicate screenshot frame events

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

* test(browser): preserve unknown with-scope loader bindings

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>

---------

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-06 02:10:00 +08:00
committed by GitHub
parent 864205570a
commit 1bd641d39f
4 changed files with 67 additions and 3 deletions
+24 -2
View File
@@ -56,7 +56,15 @@ export const captureCdpScreenshot = async (
const mainFrame = captureFrames(before, origins, 1).items[0];
if (authorized === undefined || mainFrame === undefined)
throw new BrowserObservationError("inspect_web_page", "target_not_allowed");
const navigation = { changed: false, leftScope: false };
const initialFrame = recordValue(
recordValue(recordValue(before)?.frameTree)?.frame,
);
const navigation = {
changed: false,
leftScope: false,
url: beforeUrl,
loaderId: stringValue(initialFrame?.loaderId),
};
const removeListener = context.connection.onEvent((event) => {
if (event.sessionId !== context.sessionId) return;
observeScreenshotNavigation(event, mainFrame.frame_id, origins, navigation);
@@ -125,13 +133,27 @@ const observeScreenshotNavigation = (
event: CdpEvent,
mainFrameId: string,
origins: ReadonlySet<string>,
state: { changed: boolean; leftScope: boolean },
state: {
changed: boolean;
leftScope: boolean;
readonly url: string | undefined;
readonly loaderId: string | undefined;
},
): void => {
if (!isMainFrameNavigation(event, mainFrameId)) return;
const params = recordValue(event.params);
if (params === undefined) return;
const frame =
event.method === "Page.frameNavigated" ? recordValue(params.frame) : params;
if (
event.method === "Page.frameNavigated" &&
state.loaderId !== undefined &&
state.loaderId !== "" &&
stringValue(frame?.loaderId) === state.loaderId &&
stringValue(frame?.url) === state.url
)
return;
state.changed = true;
if (allowedSanitizedUrl(frame?.url, origins) === undefined)
state.leftScope = true;