From dff49b919d83ec83e13b25c3170be37798379c89 Mon Sep 17 00:00:00 2001 From: Vitali Zaidman Date: Tue, 28 Jan 2025 16:53:25 +0000 Subject: [PATCH] add sourceUrl content to source infos for parsed source maps --- front_end/core/sdk/SourceMap.ts | 10 ++++++---- front_end/core/sdk/SourceMapManager.ts | 27 +++++++++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/front_end/core/sdk/SourceMap.ts b/front_end/core/sdk/SourceMap.ts index 7500e04237b..16fa4e8d14a 100644 --- a/front_end/core/sdk/SourceMap.ts +++ b/front_end/core/sdk/SourceMap.ts @@ -165,7 +165,7 @@ export class SourceMap { */ constructor( compiledURL: Platform.DevToolsPath.UrlString, sourceMappingURL: Platform.DevToolsPath.UrlString, - payload: SourceMapV3) { + payload: SourceMapV3, sourceContent: string) { this.#json = payload; this.#compiledURLInternal = compiledURL; this.#sourceMappingURL = sourceMappingURL; @@ -178,7 +178,9 @@ export class SourceMap { `SourceMap "${sourceMappingURL}" contains unsupported "URL" field in one of its sections.`); } } - this.eachSection(this.parseSources.bind(this)); + this.eachSection((sourceMapObject: SourceMapV3Object) => { + this.parseSources(sourceMapObject, sourceContent); + }); } compiledURL(): Platform.DevToolsPath.UrlString { @@ -439,7 +441,7 @@ export class SourceMap { } } - private parseSources(sourceMap: SourceMapV3Object): void { + private parseSources(sourceMap: SourceMapV3Object, sourceContent: string): void { const sourceRoot = sourceMap.sourceRoot ?? ''; const ignoreList = new Set(sourceMap.ignoreList ?? sourceMap.x_google_ignoreList); for (let i = 0; i < sourceMap.sources.length; ++i) { @@ -458,7 +460,7 @@ export class SourceMap { } const url = Common.ParsedURL.ParsedURL.completeURL(this.#baseURL, href) || (href as Platform.DevToolsPath.UrlString); - const source = sourceMap.sourcesContent && sourceMap.sourcesContent[i]; + const source = sourceMap.sourcesContent && sourceMap.sourcesContent[i] || sourceContent; const sourceInfo: SourceInfo = { sourceURL: url, content: source ?? null, diff --git a/front_end/core/sdk/SourceMapManager.ts b/front_end/core/sdk/SourceMapManager.ts index fc3566949fb..55ccb15eab1 100644 --- a/front_end/core/sdk/SourceMapManager.ts +++ b/front_end/core/sdk/SourceMapManager.ts @@ -109,10 +109,10 @@ export class SourceMapManager extends Common.ObjectWr this.#attachingClient = null; const initiator = client.createPageResourceLoadInitiator(); clientData.sourceMapPromise = - loadSourceMap(sourceMapURL, initiator) + loadSourceMap(sourceURL, sourceMapURL, initiator) .then( - payload => { - const sourceMap = new SourceMap(sourceURL, sourceMapURL, payload); + ({fetchedSourceContent, parsedSourceMap}) => { + const sourceMap = new SourceMap(sourceURL, sourceMapURL, parsedSourceMap, fetchedSourceContent); if (this.#clientData.get(client) === clientData) { clientData.sourceMap = sourceMap; this.#sourceMaps.set(sourceMap, client); @@ -175,12 +175,25 @@ export class SourceMapManager extends Common.ObjectWr } async function loadSourceMap( - url: Platform.DevToolsPath.UrlString, initiator: PageResourceLoadInitiator): Promise { + sourceURL: Platform.DevToolsPath.UrlString, + sourceMapURL: Platform.DevToolsPath.UrlString, + initiator: PageResourceLoadInitiator +): Promise<{fetchedSourceContent: string, parsedSourceMap: SourceMapV3}> { try { - const {content} = await PageResourceLoader.instance().loadResource(url, initiator); - return parseSourceMap(content); + const [ + {content: sourceContent}, + {content: sourceMapContent} + ] = await Promise.all([ + PageResourceLoader.instance().loadResource(sourceURL, initiator), + PageResourceLoader.instance().loadResource(sourceMapURL, initiator) + ]); + // TODO: error handling, caching. + return { + fetchedSourceContent: sourceContent, + parsedSourceMap: parseSourceMap(sourceMapContent), + }; } catch (cause) { - throw new Error(`Could not load content for ${url}: ${cause.message}`, {cause}); + throw new Error(`Could not load content for ${sourceMapURL}: ${cause.message}`, {cause}); } }