File tree Expand file tree Collapse file tree
react-devtools-extensions/src/main
react-devtools-shared/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/* global chrome */
22
3+ import { normalizeUrlIfValid } from 'react-devtools-shared/src/utils' ;
34import { __DEBUG__ } from 'react-devtools-shared/src/constants' ;
45
56let debugIDCounter = 0 ;
@@ -116,7 +117,7 @@ async function fetchFileWithCaching(url: string): Promise<string> {
116117 chrome . devtools . inspectedWindow . getResources ( r => resolve ( r ) ) ,
117118 ) ;
118119
119- const normalizedReferenceURL = new URL ( url ) . toString ( ) ;
120+ const normalizedReferenceURL = normalizeUrlIfValid ( url ) ;
120121 const resource = resources . find ( r => r . url === normalizedReferenceURL ) ;
121122
122123 if ( resource != null ) {
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
1616 LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY ,
1717} from 'react-devtools-shared/src/constants' ;
1818import { logEvent } from 'react-devtools-shared/src/Logger' ;
19+ import { normalizeUrlIfValid } from 'react-devtools-shared/src/utils' ;
1920
2021import {
2122 setBrowserSelectionFromReact ,
@@ -129,9 +130,7 @@ function createBridgeAndStore() {
129130
130131 // We use 1-based line and column, Chrome expects them 0-based.
131132 chrome . devtools . panels . openResource (
132- // openResource needs normalized URLs.
133- // Using `URL` triggers path normalization.
134- new URL ( sourceURL ) . toString ( ) ,
133+ normalizeUrlIfValid ( sourceURL ) ,
135134 line - 1 ,
136135 column - 1 ,
137136 ) ;
Original file line number Diff line number Diff line change @@ -996,6 +996,19 @@ export function backendToFrontendSerializedElementMapper(
996996 } ;
997997}
998998
999+ /**
1000+ * Should be used when treating url as a Chrome Resource URL.
1001+ */
1002+ export function normalizeUrlIfValid ( url : string ) : string {
1003+ try {
1004+ return new URL ( url ) . toString ( ) ;
1005+ } catch {
1006+ // Giving up if it's not a valid URL without basepath
1007+ // TODO: Chrome will use the basepath to create a Resource URL.
1008+ return url ;
1009+ }
1010+ }
1011+
9991012export function getIsReloadAndProfileSupported ( ) : boolean {
10001013 // Notify the frontend if the backend supports the Storage API (e.g. localStorage).
10011014 // If not, features like reload-and-profile will not work correctly and must be disabled.
You can’t perform that action at this time.
0 commit comments