@@ -27,8 +27,12 @@ export interface Script {
2727 url ?: string ;
2828 sourceUrl ?: string ;
2929 content ?: string ;
30- /** Note: this is the literal text given as the sourceMappingURL value. It has not been resolved relative to the script url. */
30+ /** Note: this is the literal text given as the sourceMappingURL value. It has not been resolved relative to the script url.
31+ * Since M138, data urls are never set here.
32+ */
3133 sourceMapUrl ?: string ;
34+ /** If true, the source map url was a data URL, so it got removed from the trace event. */
35+ sourceMapUrlElided ?: boolean ;
3236 sourceMap ?: SDK . SourceMap . SourceMap ;
3337 request ?: Types . Events . SyntheticNetworkRequest ;
3438 /** Lazily generated - use getScriptGeneratedSizes to access. */
@@ -67,13 +71,21 @@ export function handleEvent(event: Types.Events.Event): void {
6771 }
6872
6973 if ( Types . Events . isV8SourceRundownEvent ( event ) ) {
70- const { isolate, scriptId, url, sourceUrl, sourceMapUrl} = event . args . data ;
74+ const { isolate, scriptId, url, sourceUrl, sourceMapUrl, sourceMapUrlElided } = event . args . data ;
7175 const script = getOrMakeScript ( isolate , scriptId ) ;
7276 script . url = url ;
7377 if ( sourceUrl ) {
7478 script . sourceUrl = sourceUrl ;
7579 }
76- if ( sourceMapUrl ) {
80+
81+ // Older traces may have data source map urls. Those can be very large, so a change
82+ // was made to elide them from the trace.
83+ // If elided, a fresh trace will fetch the source map from the Script model
84+ // (see TimelinePanel getExistingSourceMap). If not fresh, the source map is resolved
85+ // instead in this handler via `findCachedRawSourceMap`.
86+ if ( sourceMapUrlElided ) {
87+ script . sourceMapUrlElided = true ;
88+ } else if ( sourceMapUrl ) {
7789 script . sourceMapUrl = sourceMapUrl ;
7890 }
7991 return ;
@@ -199,17 +211,37 @@ export function getScriptGeneratedSizes(script: Script): GeneratedFileSizes|null
199211 return script . sizes ?? null ;
200212}
201213
202- function findCachedRawSourceMap (
203- sourceMapUrl : string , options : Types . Configuration . ParseOptions ) : SDK . SourceMap . SourceMapV3 | undefined {
204- if ( ! sourceMapUrl ) {
214+ function findCachedRawSourceMap ( script : Script , options : Types . Configuration . ParseOptions ) : SDK . SourceMap . SourceMapV3 |
215+ undefined {
216+ if ( options . isFreshRecording || ! options . metadata ?. sourceMaps ) {
217+ // Exit if this is not a loaded trace w/ source maps in the metadata.
218+ return ;
219+ }
220+
221+ // For elided data url source maps, search the metadata source maps by script url.
222+ if ( script . sourceMapUrlElided ) {
223+ if ( ! script . url ) {
224+ return ;
225+ }
226+
227+ const cachedSourceMap = options . metadata . sourceMaps . find ( m => m . url === script . url ) ;
228+ if ( cachedSourceMap ) {
229+ return cachedSourceMap . sourceMap ;
230+ }
231+
205232 return ;
206233 }
207234
208- // If loading from disk, check the metadata for source maps.
209- // The metadata doesn't store data url source maps.
210- const isDataUrl = sourceMapUrl . startsWith ( 'data:' ) ;
211- if ( ! options . isFreshRecording && options . metadata ?. sourceMaps && ! isDataUrl ) {
212- const cachedSourceMap = options . metadata . sourceMaps . find ( m => m . sourceMapUrl === sourceMapUrl ) ;
235+ if ( ! script . sourceMapUrl ) {
236+ return ;
237+ }
238+
239+ // Otherwise, search by source map url.
240+ // Note: early enhanced traces may have this field set for data urls. Ignore those,
241+ // as they were never stored in metadata sourcemap.
242+ const isDataUrl = script . sourceMapUrl . startsWith ( 'data:' ) ;
243+ if ( ! isDataUrl ) {
244+ const cachedSourceMap = options . metadata . sourceMaps . find ( m => m . sourceMapUrl === script . sourceMapUrl ) ;
213245 if ( cachedSourceMap ) {
214246 return cachedSourceMap . sourceMap ;
215247 }
@@ -243,7 +275,7 @@ export async function finalize(options: Types.Configuration.ParseOptions): Promi
243275 // No frame or url means the script came from somewhere we don't care about.
244276 // Note: scripts from inline <SCRIPT> elements use the url of the HTML document,
245277 // so aren't ignored.
246- if ( ! script . frame || ! script . url || ! script . sourceMapUrl ) {
278+ if ( ! script . frame || ! script . url || ( ! script . sourceMapUrl && ! script . sourceMapUrlElided ) ) {
247279 continue ;
248280 }
249281
@@ -259,22 +291,26 @@ export async function finalize(options: Types.Configuration.ParseOptions): Promi
259291 sourceUrl = Common . ParsedURL . ParsedURL . completeURL ( frameUrl , script . sourceUrl ) ?? script . sourceUrl ;
260292 }
261293
262- // Resolve the source map url. The value given by v8 may be relative, so resolve it here.
263- // This process should match the one in `SourceMapManager.attachSourceMap`.
264- const sourceMapUrl =
265- Common . ParsedURL . ParsedURL . completeURL ( sourceUrl as Platform . DevToolsPath . UrlString , script . sourceMapUrl ) ;
266- if ( ! sourceMapUrl ) {
267- continue ;
268- }
294+ let sourceMapUrl ;
295+ if ( script . sourceMapUrl ) {
296+ // Resolve the source map url. The value given by v8 may be relative, so resolve it here.
297+ // This process should match the one in `SourceMapManager.attachSourceMap`.
298+ sourceMapUrl =
299+ Common . ParsedURL . ParsedURL . completeURL ( sourceUrl as Platform . DevToolsPath . UrlString , script . sourceMapUrl ) ;
300+ if ( ! sourceMapUrl ) {
301+ continue ;
302+ }
269303
270- script . sourceMapUrl = sourceMapUrl ;
304+ script . sourceMapUrl = sourceMapUrl ;
305+ }
271306
272307 const params : Types . Configuration . ResolveSourceMapParams = {
273308 scriptId : script . scriptId ,
274- scriptUrl : sourceUrl as Platform . DevToolsPath . UrlString ,
275- sourceMapUrl : sourceMapUrl as Platform . DevToolsPath . UrlString ,
309+ scriptUrl : script . url as Platform . DevToolsPath . UrlString ,
310+ sourceUrl : sourceUrl as Platform . DevToolsPath . UrlString ,
311+ sourceMapUrl : sourceMapUrl ?? '' as Platform . DevToolsPath . UrlString ,
276312 frame : script . frame as Protocol . Page . FrameId ,
277- cachedRawSourceMap : findCachedRawSourceMap ( sourceMapUrl , options ) ,
313+ cachedRawSourceMap : findCachedRawSourceMap ( script , options ) ,
278314 } ;
279315 const promise = options . resolveSourceMap ( params ) . then ( sourceMap => {
280316 if ( sourceMap ) {
0 commit comments