perf: reduce MCP launcher and browser capture overhead (#4350)
* perf(browser): 为单次捕获复用脚本资源索引 * docs(setup): 说明多会话直接启动以减少 npm 驻留
This commit is contained in:
1 parent
509d4c8f56
commit
0cd4eafd61
4 files changed
+157
-49
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import type { WebPageInspection } from "../domain/browserObservationSchemas.js";
|
||||
import {
|
||||
reconcileCapturedWebScript,
|
||||
createCapturedWebScriptReconciler,
|
||||
stableWebScriptKey,
|
||||
} from "../domain/webInventory.js";
|
||||
import type { CapturedResource } from "./CdpCaptureDocuments.js";
|
||||
@@ -32,8 +32,9 @@ interface ScriptDraftState {
|
||||
readonly context: CaptureContext;
|
||||
readonly events: CdpCaptureEvents;
|
||||
readonly frameIds: ReadonlySet<string>;
|
||||
readonly rawResources: readonly CapturedResource[];
|
||||
readonly resources: WebPageInspection["resources"];
|
||||
readonly reconcileResource: ReturnType<
|
||||
typeof createCapturedWebScriptReconciler
|
||||
>;
|
||||
}
|
||||
|
||||
type ScriptDraftItem = Omit<
|
||||
@@ -45,19 +46,23 @@ export const captureScripts = async (
|
||||
options: CaptureScriptsOptions,
|
||||
): Promise<CapturedScripts> => {
|
||||
const { context, events, rawResources, resources, frameIds } = options;
|
||||
const state: ScriptDraftState = {
|
||||
context,
|
||||
events,
|
||||
frameIds,
|
||||
rawResources,
|
||||
resources,
|
||||
};
|
||||
let state: ScriptDraftState | undefined;
|
||||
const drafts: {
|
||||
readonly item: ScriptDraftItem;
|
||||
readonly sourceMapRawUrl: string | null;
|
||||
}[] = [];
|
||||
for (const script of events.scripts.values())
|
||||
for (const script of events.scripts.values()) {
|
||||
state ??= {
|
||||
context,
|
||||
events,
|
||||
frameIds,
|
||||
reconcileResource: createCapturedWebScriptReconciler(
|
||||
rawResources,
|
||||
resources,
|
||||
),
|
||||
};
|
||||
drafts.push(await buildScriptDraft(script, state));
|
||||
}
|
||||
if (!context.input.include_script_sources)
|
||||
events.completeness.exclude(
|
||||
"script_sources",
|
||||
@@ -91,11 +96,10 @@ const buildScriptDraft = async (
|
||||
item: {
|
||||
...inventoryScript,
|
||||
origin: script.origin,
|
||||
resource_reconciliation: reconcileCapturedWebScript(
|
||||
{ ...inventoryScript, rawUrl: script.rawUrl },
|
||||
state.rawResources,
|
||||
state.resources,
|
||||
),
|
||||
resource_reconciliation: state.reconcileResource({
|
||||
...inventoryScript,
|
||||
rawUrl: script.rawUrl,
|
||||
}),
|
||||
source,
|
||||
},
|
||||
sourceMapRawUrl: script.sourceMapRawUrl,
|
||||
|
||||
Reference in new issue
Block a user