Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/devtools_app/web/flutter_bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{flutter_js}}
{{flutter_build_config}}

// Unregister the old custom DevTools service worker (if it exists). It was
// removed in: https://github.com/flutter/devtools/pull/5331
function unregisterDevToolsServiceWorker() {
if ('serviceWorker' in navigator) {
const DEVTOOLS_SW = 'service_worker.js';
const FLUTTER_SW = 'flutter_service_worker.js';
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for (let registration of registrations) {
const activeWorker = registration.active;
if (activeWorker != null) {
const url = activeWorker.scriptURL;
if (url.includes(DEVTOOLS_SW) && !url.includes(FLUTTER_SW)) {
registration.unregister();
}
}
}
});
}
}

// Bootstrap app for 3P environments:
function bootstrapAppFor3P() {
_flutter.loader.load({
serviceWorkerSettings: {
serviceWorkerVersion: {{flutter_service_worker_version}},
},
config: {
canvasKitBaseUrl: 'canvaskit/'
}
});
}

// Bootstrap app for 1P environments:
function bootstrapAppFor1P() {
_flutter.loader.load();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing we also need to specify the entrypointUrl as main.dart.js, see #5705

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not need that, and the new API does not take an entryPointUrl as a parameter. The old API should have had that as the default and wouldn't have needed that anyway, so I'm not sure why that was needed before.

}

unregisterDevToolsServiceWorker();
bootstrapAppFor3P();
72 changes: 1 addition & 71 deletions packages/devtools_app/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,83 +50,13 @@
}
</script>

<script>
// The value below is injected by flutter build, do not touch.
var serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>

<!-- TODO(elliette): Remove once https://github.com/flutter/flutter/issues/122541 is fixed. -->
<link rel="stylesheet" href="styles.css">

</head>

<body>

<script>
// Unregister the old custom DevTools service worker (if it exists). It was
// removed in: https://github.com/flutter/devtools/pull/5331
function unregisterDevToolsServiceWorker() {
if ('serviceWorker' in navigator) {
const DEVTOOLS_SW = 'service_worker.js';
const FLUTTER_SW = 'flutter_service_worker.js';
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for (let registration of registrations) {
const activeWorker = registration.active;
if (activeWorker != null) {
const url = activeWorker.scriptURL;
if (url.includes(DEVTOOLS_SW) && !url.includes(FLUTTER_SW)) {
registration.unregister();
}
}
}
});
}
}

// Bootstrap app for 3P environments:
function bootstrapAppFor3P() {
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine({
renderer: 'canvaskit',
canvasKitBaseUrl: 'canvaskit/'
})
.then(function(appRunner) {
appRunner.runApp();
});
}
});
});
}

// Bootstrap app for 1P environments:
function bootstrapAppFor1P() {
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
entrypointUrl: 'main.dart.js',
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine({
renderer: 'canvaskit',
})
.then(function(appRunner) {
appRunner.runApp();
});
}
});
});
}

unregisterDevToolsServiceWorker();
bootstrapAppFor3P();
</script>
<script src="flutter_bootstrap.js" async></script>
</body>

</html>