Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

perf(browser): parse captured module URLs once per lookup (#1829)

Shayan Alica11162d027a
diff --git a/src/domain/webModuleImports.test.ts b/src/domain/webModuleImports.test.ts
index 346938a4e..26db977a1 100644
--- a/src/domain/webModuleImports.test.ts
+++ b/src/domain/webModuleImports.test.ts
@@ -142,4 +142,20 @@ describe("captured module candidates", () => {
),
).toEqual([]);
});
+ it("retains exact non-URL identities without matching response fragments", () => {
+ const scripts = [
+ script("relative/module.js#part", "page-script"),
+ script("relative/module.js#part", "scenario-response"),
+ script("relative/module.js", "scenario-response"),
+ ];
+ expect(
+ matchCapturedModules("relative/module.js#part", scripts).map((item) => [
+ item.script_index,
+ item.match,
+ ]),
+ ).toEqual([
+ [0, "exact-reported-url"],
+ [1, "exact-reported-url"],
+ ]);
+ });
});
diff --git a/src/domain/webModuleImports.ts b/src/domain/webModuleImports.ts
index fdcd36e83..026868955 100644
--- a/src/domain/webModuleImports.ts
+++ b/src/domain/webModuleImports.ts
@@ -108,6 +108,8 @@ export const matchCapturedModules = (
url: string,
scripts: readonly ExportedWebScript[],
) => {
+ const transport = URL.parse(url);
+ if (transport !== null) transport.hash = "";
const candidates: {
script_index: number;
match: "exact-reported-url" | "response-url-without-fragment";
@@ -116,20 +118,15 @@ export const matchCapturedModules = (
scripts.forEach((script, script_index) => {
if (script.url === url)
candidates.push({ script_index, match: "exact-reported-url", script });
- else if (script.source.kind === "scenario-response") {
- try {
- const transport = new URL(url);
- transport.hash = "";
- if (transport.href === script.url)
- candidates.push({
- script_index,
- match: "response-url-without-fragment",
- script,
- });
- } catch (cause: unknown) {
- void cause;
- }
- }
+ else if (
+ script.source.kind === "scenario-response" &&
+ transport?.href === script.url
+ )
+ candidates.push({
+ script_index,
+ match: "response-url-without-fragment",
+ script,
+ });
});
return candidates;
};