fix(browser): ignore duplicate frame navigations and read block-form source map directives (#546)
This commit is contained in:
@@ -367,8 +367,15 @@ export const handleFrameNavigated = (
|
||||
): void => {
|
||||
const frame = recordValue(params.frame);
|
||||
if (stringValue(frame?.id) !== state.mainFrameId) return;
|
||||
state.navigationDuringCapture = true;
|
||||
const rawUrl = stringValue(frame?.url);
|
||||
const loaderId = stringValue(frame?.loaderId);
|
||||
// `frameNavigated` re-fires for a document already reported (same URL and
|
||||
// loader). Treating that as a navigation aborted a valid capture with
|
||||
// `target_changed`, which is a false claim that the target moved.
|
||||
const document = `${String(loaderId ?? "")}\0${String(rawUrl ?? "")}`;
|
||||
if (state.committedDocument === document) return;
|
||||
state.committedDocument = document;
|
||||
state.navigationDuringCapture = true;
|
||||
if (
|
||||
isHttpUrl(rawUrl) &&
|
||||
allowedSanitizedUrl(rawUrl, state.allowedOrigins) === undefined
|
||||
|
||||
@@ -20,4 +20,10 @@ export interface CdpCaptureEventsState {
|
||||
originViolation: boolean;
|
||||
navigationDuringCapture: boolean;
|
||||
mainFrameId: string | undefined;
|
||||
/**
|
||||
* Identity of the document last observed in the main frame. `frameNavigated`
|
||||
* re-fires for the same document, so this is what distinguishes a real
|
||||
* document change from a duplicate event.
|
||||
*/
|
||||
committedDocument: string | undefined;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ export class CdpCaptureEvents implements CdpCaptureEventsState {
|
||||
originViolation = false;
|
||||
navigationDuringCapture = false;
|
||||
mainFrameId: string | undefined = undefined;
|
||||
committedDocument: string | undefined = undefined;
|
||||
|
||||
readonly input: InspectWebPageInput;
|
||||
readonly allowedOrigins: ReadonlySet<string>;
|
||||
@@ -46,6 +47,7 @@ export class CdpCaptureEvents implements CdpCaptureEventsState {
|
||||
this.mainFrameId = frameId;
|
||||
this.originViolation = false;
|
||||
this.navigationDuringCapture = false;
|
||||
this.committedDocument = undefined;
|
||||
this.scripts.clear();
|
||||
this.executionContextFrames.clear();
|
||||
this.network.clear();
|
||||
@@ -65,7 +67,14 @@ export class CdpCaptureEvents implements CdpCaptureEventsState {
|
||||
|
||||
beginFinalCapture(frameId: string): void {
|
||||
this.mainFrameId = frameId;
|
||||
this.navigationDuringCapture = false;
|
||||
// Deliberately does not clear `navigationDuringCapture`. A main-frame
|
||||
// navigation observed during the observation window means the page never
|
||||
// settled, and clearing the flag here reported the capture as clean while
|
||||
// carrying pre-navigation scripts, network and console into the inventory
|
||||
// of the new document. The caller now reports `target_changed` instead.
|
||||
// `committedDocument` is dropped so the new document's frame events are
|
||||
// compared against itself rather than the document we just left.
|
||||
this.committedDocument = undefined;
|
||||
}
|
||||
|
||||
ingest(event: CdpEvent): void {
|
||||
|
||||
Reference in New Issue
Block a user