Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(browser): preserve source-map media types (#4032)
Can536f5ce38b70
diff --git a/src/browser/WebSourceMapFetcher.ts b/src/browser/WebSourceMapFetcher.tsindex d3a698a7c..47aa00aa6 100644--- a/src/browser/WebSourceMapFetcher.ts+++ b/src/browser/WebSourceMapFetcher.ts@@ -622,6 +622,7 @@ const normalizeSourceMap = (const sanitized =resolved === null ? null : cachedSanitized(sourcesByRaw, resolved);const content = leaf.map.sourcesContent?.[index] ?? null;+ const mediaType = sourceMediaType(resolved ?? rawSource);consumeExpandedBytes(context.budget,(sanitized === null@@ -632,7 +633,7 @@ const normalizeSourceMap = ((content === null? 0: jsonBytes(content) +- artifactMetadataBytes(sourceMediaType(rawSource), content) -+ artifactMetadataBytes(mediaType, content) -4),);originalSources.push({@@ -640,9 +641,7 @@ const normalizeSourceMap = (declaration_index: declarationIndex++,source: sanitized,artifact:- content === null- ? null- : createWebTextArtifact(content, sourceMediaType(rawSource)),+ content === null ? null : createWebTextArtifact(content, mediaType),});}}@@ -776,7 +775,7 @@ const originalModuleEdges = (}const parsed = parseJavaScriptSource(source.artifact.text,- sourceParserPath(sourceName),+ originalSourcePath(sourceName),);check();if (parsed === null) {@@ -831,8 +830,8 @@ const originalModuleEdges = (return { edges, incomplete };};-/** Select parser semantics from the source URL path, excluding query/fragment. */-const sourceParserPath = (source: string): string => {+/** Select source language from the URL path, excluding query/fragment. */+const originalSourcePath = (source: string): string => {try {return new URL(source).pathname;} catch (cause: unknown) {@@ -1088,13 +1087,15 @@ const resolveOriginalSource = (}};-const sourceMediaType = (source: string | null): string =>- source?.endsWith(".ts") ||- source?.endsWith(".tsx") ||- source?.endsWith(".mts") ||- source?.endsWith(".cts")+const sourceMediaType = (source: string | null): string => {+ const path = source === null ? null : originalSourcePath(source);+ return path?.endsWith(".ts") ||+ path?.endsWith(".tsx") ||+ path?.endsWith(".mts") ||+ path?.endsWith(".cts")? "text/typescript": "text/javascript";+};const originalDependency = (node: t.Node,diff --git a/tests/boundary/browser/webSourceMapFetcher.test.ts b/tests/boundary/browser/webSourceMapFetcher.test.tsindex a030b76b6..796713f0f 100644--- a/tests/boundary/browser/webSourceMapFetcher.test.ts+++ b/tests/boundary/browser/webSourceMapFetcher.test.ts@@ -1779,6 +1779,17 @@ describe("source-map original artifact language metadata", () => {["main.js", "text/javascript"],["main.mjs", "text/javascript"],["main.cjs", "text/javascript"],+ ["main.ts?revision=2", "text/typescript"],+ ["main.tsx?revision=2", "text/typescript"],+ ["main.mts?revision=2", "text/typescript"],+ ["main.cts?revision=2", "text/typescript"],+ ["main.ts#original", "text/typescript"],+ ["main.tsx#original", "text/typescript"],+ ["main.mts#original", "text/typescript"],+ ["main.cts#original", "text/typescript"],+ ["main.js?filename=main.ts", "text/javascript"],+ ["main.js#main.ts", "text/javascript"],+ ["extensionless?revision=2", "text/javascript"],])("retains the source language for %s", async (filename, mediaType) => {const text =mediaType === "text/typescript"@@ -1818,7 +1829,12 @@ describe("source-map original artifact language metadata", () => {original_sources: [{source: `${localOrigin}/${filename}`,- artifact: { media_type: mediaType, text },+ artifact: {+ media_type: mediaType,+ text,+ bytes: Buffer.byteLength(text),+ sha256: createHash("sha256").update(text).digest("hex"),+ },},],mappings: [{ source: `${localOrigin}/${filename}` }],diff --git a/tests/boundary/mcp/browserMcp.test.ts b/tests/boundary/mcp/browserMcp.test.tsindex 48593e4ef..4f6ffc442 100644--- a/tests/boundary/mcp/browserMcp.test.ts+++ b/tests/boundary/mcp/browserMcp.test.ts@@ -356,13 +356,25 @@ const assertScreenshotPngFailures = async (client: Client): Promise<void> => {it("delivers the source-map response URL through authenticated MCP Evidence", async () => {const terminalPath = "/maps/v1/app.js.map?revision=2&token=source-value";+ const sources = [+ ["../src/original.js", "text/javascript"],+ ["../src/plain.ts", "text/typescript"],+ ["../src/main.ts?revision=2", "text/typescript"],+ ["../src/main.tsx?revision=2", "text/typescript"],+ ["../src/main.mts?revision=2", "text/typescript"],+ ["../src/main.cts?revision=2", "text/typescript"],+ ["../src/fragment.ts#original", "text/typescript"],+ ["../src/control.js?filename=main.ts", "text/javascript"],+ ["../src/extensionless?revision=2", "text/javascript"],+ ] as const;+ const sourceText = "export const value = 1;";const browser = await startFakeCdpBrowser({sourceMapRedirect: terminalPath,sourceMapBody: JSON.stringify({version: 3,names: [],- sources: ["../src/original.js"],- sourcesContent: ["export const value = 1;"],+ sources: sources.map(([source]) => source),+ sourcesContent: sources.map(() => sourceText),mappings: "AAAA",}),});@@ -388,9 +400,11 @@ it("delivers the source-map response URL through authenticated MCP Evidence", as{declared_url: `${browser.allowedOrigin}/app.js.map?token=map-secret`,effective_url: `${browser.allowedOrigin}${terminalPath}`,- original_sources: [- { source: `${browser.allowedOrigin}/maps/src/original.js` },- ],+ original_sources: sources.map(([source, mediaType]) => ({+ source: new URL(source, `${browser.allowedOrigin}${terminalPath}`)+ .href,+ artifact: { media_type: mediaType, text: sourceText },+ })),},],},