Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sourceUrl content to source infos for parsed source maps #195

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions front_end/core/sdk/SourceMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
27 changes: 20 additions & 7 deletions front_end/core/sdk/SourceMapManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ export class SourceMapManager<T extends FrameAssociated> 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);
Expand Down Expand Up @@ -175,12 +175,25 @@ export class SourceMapManager<T extends FrameAssociated> extends Common.ObjectWr
}

async function loadSourceMap(
url: Platform.DevToolsPath.UrlString, initiator: PageResourceLoadInitiator): Promise<SourceMapV3> {
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});
}
}

Expand Down