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() {
Copy link
Member

@elliette elliette May 30, 2024

Choose a reason for hiding this comment

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

Do we need this with cl/638797386?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would opt to leave it so that things can work without needing to change anything once b/343786318 is resolved.

_flutter.loader.load();
}

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>