@@ -22,9 +22,15 @@ function unregisterDevToolsServiceWorker() {
2222}
2323
2424// This query parameter must match the String value specified by
25- // `DevToolsQueryParameters.wasmKey `. See
25+ // `DevToolsQueryParameters.compilerKey `. See
2626// devtools/packages/devtools_app/lib/src/shared/query_parameters.dart
27- const wasmQueryParameterKey = 'wasm' ;
27+ const compilerQueryParameterKey = 'compiler' ;
28+
29+ // Returns the value for the given search param.
30+ function getSearchParam ( searchParamKey ) {
31+ const searchParams = new URLSearchParams ( window . location . search ) ;
32+ return searchParams . get ( searchParamKey ) ;
33+ }
2834
2935// Calls the DevTools server API to read the user's wasm preference.
3036async function getDevToolsWasmPreference ( ) {
@@ -49,12 +55,20 @@ async function getDevToolsWasmPreference() {
4955 }
5056}
5157
58+ // The query parameter compiler=js gives us an escape hatch we can offer users if their
59+ // dart2wasm app fails to load.
60+ const forceUseJs = ( ) => getSearchParam ( compilerQueryParameterKey ) === 'js' ;
61+
5262// Returns whether DevTools should be loaded with the skwasm renderer based on the
5363// value of the 'wasm' query parameter or the wasm setting from the DevTools
5464// preference file.
5565async function shouldUseSkwasm ( ) {
56- const searchParams = new URLSearchParams ( window . location . search ) ;
57- const wasmEnabledFromQueryParameter = searchParams . get ( wasmQueryParameterKey ) === 'true' ;
66+ // If dart2js has specifically been requested via query parameter, then do not try to
67+ // use skwasm (even if the local setting is for wasm).
68+ if ( forceUseJs ( ) ) {
69+ return false ;
70+ }
71+ const wasmEnabledFromQueryParameter = getSearchParam ( compilerQueryParameterKey ) === 'wasm' ;
5872 const wasmEnabledFromDevToolsPreference = await getDevToolsWasmPreference ( ) ;
5973 return wasmEnabledFromQueryParameter === true || wasmEnabledFromDevToolsPreference === true ;
6074}
@@ -64,9 +78,9 @@ async function shouldUseSkwasm() {
6478function updateWasmQueryParameter ( useSkwasm ) {
6579 const url = new URL ( window . location . href ) ;
6680 if ( useSkwasm ) {
67- url . searchParams . set ( wasmQueryParameterKey , 'true ' ) ;
81+ url . searchParams . set ( compilerQueryParameterKey , 'wasm ' ) ;
6882 } else {
69- url . searchParams . delete ( wasmQueryParameterKey ) ;
83+ url . searchParams . delete ( compilerQueryParameterKey ) ;
7084 }
7185 // Update the browser's history without reloading. This is a no-op if the wasm
7286 // query parameter does not actually need to be updated.
@@ -77,9 +91,11 @@ function updateWasmQueryParameter(useSkwasm) {
7791async function bootstrapAppFor3P ( ) {
7892 const useSkwasm = await shouldUseSkwasm ( ) ;
7993
80- // Ensure the 'wasm' query parameter in the URL is accurate for the renderer
81- // DevTools will be loaded with.
82- updateWasmQueryParameter ( useSkwasm ) ;
94+ if ( ! forceUseJs ( ) ) {
95+ // Ensure the 'wasm' query parameter in the URL is accurate for the renderer
96+ // DevTools will be loaded with.
97+ updateWasmQueryParameter ( useSkwasm ) ;
98+ }
8399
84100 const rendererForLog = useSkwasm ? 'skwasm' : 'canvaskit' ;
85101 console . log ( 'Attempting to load DevTools with ' + rendererForLog + ' renderer.' ) ;
0 commit comments