@@ -22,9 +22,15 @@ function unregisterDevToolsServiceWorker() {
22
22
}
23
23
24
24
// This query parameter must match the String value specified by
25
- // `DevToolsQueryParameters.wasmKey `. See
25
+ // `DevToolsQueryParameters.compilerKey `. See
26
26
// 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
+ }
28
34
29
35
// Calls the DevTools server API to read the user's wasm preference.
30
36
async function getDevToolsWasmPreference ( ) {
@@ -49,12 +55,20 @@ async function getDevToolsWasmPreference() {
49
55
}
50
56
}
51
57
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
+
52
62
// Returns whether DevTools should be loaded with the skwasm renderer based on the
53
63
// value of the 'wasm' query parameter or the wasm setting from the DevTools
54
64
// preference file.
55
65
async 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' ;
58
72
const wasmEnabledFromDevToolsPreference = await getDevToolsWasmPreference ( ) ;
59
73
return wasmEnabledFromQueryParameter === true || wasmEnabledFromDevToolsPreference === true ;
60
74
}
@@ -64,9 +78,9 @@ async function shouldUseSkwasm() {
64
78
function updateWasmQueryParameter ( useSkwasm ) {
65
79
const url = new URL ( window . location . href ) ;
66
80
if ( useSkwasm ) {
67
- url . searchParams . set ( wasmQueryParameterKey , 'true ' ) ;
81
+ url . searchParams . set ( compilerQueryParameterKey , 'wasm ' ) ;
68
82
} else {
69
- url . searchParams . delete ( wasmQueryParameterKey ) ;
83
+ url . searchParams . delete ( compilerQueryParameterKey ) ;
70
84
}
71
85
// Update the browser's history without reloading. This is a no-op if the wasm
72
86
// query parameter does not actually need to be updated.
@@ -77,9 +91,11 @@ function updateWasmQueryParameter(useSkwasm) {
77
91
async function bootstrapAppFor3P ( ) {
78
92
const useSkwasm = await shouldUseSkwasm ( ) ;
79
93
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
+ }
83
99
84
100
const rendererForLog = useSkwasm ? 'skwasm' : 'canvaskit' ;
85
101
console . log ( 'Attempting to load DevTools with ' + rendererForLog + ' renderer.' ) ;
0 commit comments