mirror of
https://github.com/morluto/rea.git
synced 2026-11-12 01:41:21 +00:00
Move each error family out of domain/errors.ts into its own module (base, core, provider selection/adapter, browser observation, artifact, evidence, unknown registry, hopper, configuration) and relocate AnalysisErrorProjection to analysisErrorProjection. Migrate all 162 importers to the owning modules and delete errors.ts. No re-export shims; behavior is unchanged.
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import type { BrowserObservationOperation } from "../domain/browserObservationErrors.js";
|
|
import { BrowserObservationError } from "../domain/browserObservationError.js";
|
|
import type { CdpConnection } from "./CdpConnection.js";
|
|
import { mainFrameUrl } from "./CdpCaptureDocuments.js";
|
|
import {
|
|
allowedSanitizedUrl,
|
|
delayWithCancellation,
|
|
isHttpUrl,
|
|
} from "./CdpCaptureValues.js";
|
|
|
|
interface AuthorizedMainFrameOptions {
|
|
readonly connection: CdpConnection;
|
|
readonly sessionId: string | undefined;
|
|
readonly signal: AbortSignal | undefined;
|
|
readonly allowedOrigins: ReadonlySet<string>;
|
|
readonly delayOperation: BrowserObservationOperation;
|
|
}
|
|
|
|
/** Wait for the attached target's main frame to enter its approved origin. */
|
|
export const authorizedMainFrame = async ({
|
|
connection,
|
|
sessionId,
|
|
signal,
|
|
allowedOrigins,
|
|
delayOperation,
|
|
}: AuthorizedMainFrameOptions): Promise<unknown> => {
|
|
for (let attempt = 0; attempt < 80; attempt += 1) {
|
|
const result = await connection.send(
|
|
"Page.getFrameTree",
|
|
{},
|
|
sessionId,
|
|
signal,
|
|
);
|
|
const url = mainFrameUrl(result);
|
|
if (allowedSanitizedUrl(url, allowedOrigins) !== undefined) return result;
|
|
if (isHttpUrl(url))
|
|
throw new BrowserObservationError(
|
|
"inspect_web_page",
|
|
"target_not_allowed",
|
|
);
|
|
await delayWithCancellation(25, delayOperation, signal);
|
|
}
|
|
throw new BrowserObservationError("inspect_web_page", "target_not_allowed");
|
|
};
|