|
1 | 1 | (function loadDevToolsScript() { |
2 | 2 | const DDR_DART_APP_ATTRIBUTE = 'data-ddr-dart-app'; |
3 | | - let created = false; |
4 | | - let checkCount = 0; |
5 | 3 |
|
6 | | - chrome.devtools.network.onNavigated.addListener(createPanelIfDartApp) |
7 | | - const checkDartAppInterval = setInterval(createPanelIfDartApp, 1000) |
8 | | - createPanelIfDartApp() |
| 4 | + let debuggerCreated = false; |
| 5 | + let inspectorCreated = false; |
| 6 | + let checkDartCount = 0; |
| 7 | + let checkFlutterCount = 0; |
9 | 8 |
|
10 | | - function createPanelIfDartApp() { |
11 | | - if (created || checkCount++ > 20) { |
| 9 | + chrome.devtools.network.onNavigated.addListener(createDebuggerPanelIfDartApp) |
| 10 | + const checkDartAppInterval = setInterval(createDebuggerPanelIfDartApp, 1000) |
| 11 | + createDebuggerPanelIfDartApp() |
| 12 | + |
| 13 | + function createDebuggerPanelIfDartApp() { |
| 14 | + if (debuggerCreated || checkDartCount++ > 20) { |
12 | 15 | clearInterval(checkDartAppInterval); |
13 | 16 | return; |
14 | 17 | } |
15 | 18 |
|
| 19 | + checkIsDartApp(); |
| 20 | + } |
| 21 | + |
| 22 | + function checkIsDartApp() { |
16 | 23 | // TODO(elliette): Remove the DDR data attribute check when we are ready to launch externally, |
17 | 24 | // and instead replace it with the following: !!window.$dartAppId |
18 | 25 | // Note: we must remove the useContentScriptContext option as well. |
19 | 26 | chrome.devtools.inspectedWindow.eval( |
20 | 27 | `document.documentElement.hasAttribute("${DDR_DART_APP_ATTRIBUTE}")`, |
21 | | - {useContentScriptContext: true}, |
| 28 | + { useContentScriptContext: true }, |
22 | 29 | function (isDartApp) { |
23 | | - if (isDartApp) { |
24 | | - created = true |
25 | | - chrome.devtools.panels.create( |
26 | | - 'Dart Debugger', '', 'panel.html' |
| 30 | + if (!isDartApp) return; |
| 31 | + |
| 32 | + chrome.devtools.panels.create( |
| 33 | + 'Dart Debugger', '', 'debugger_panel.html' |
27 | 34 | ); |
| 35 | + debuggerCreated = true; |
| 36 | + createInspectorPanelIfFlutterApp(); |
| 37 | + }); |
| 38 | + } |
| 39 | + |
| 40 | + function createInspectorPanelIfFlutterApp() { |
| 41 | + const checkFlutterAppInterval = setInterval(function () { |
| 42 | + if (inspectorCreated|| checkFlutterCount++ > 10) { |
| 43 | + clearInterval(checkFlutterAppInterval); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + // The following value is loaded asynchronously, which is why |
| 48 | + // we check for it every 1 second: |
| 49 | + chrome.devtools.inspectedWindow.eval( |
| 50 | + '!!window._flutter_web_set_location_strategy', |
| 51 | + function (isFlutterWeb) { |
| 52 | + if (isFlutterWeb) { |
| 53 | + chrome.devtools.panels.create( |
| 54 | + 'Flutter Inspector', '', 'inspector_panel.html' |
| 55 | + ); |
| 56 | + inspectorCreated = true; |
| 57 | + } |
28 | 58 | } |
29 | | - }, |
30 | | - ) |
| 59 | + ); |
| 60 | + }, 1000) |
31 | 61 | } |
32 | 62 | }()); |
33 | 63 |
|
0 commit comments