mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[tool][web] Makes flutter.js more G3 friendly. (#120504)
* Allow any JS file in flutter loader. * Nag only if service worker API is completely unavailable. * Add info about Secure Contexts if that may be the reason why serviceworker is not available. * Update sanity test. * If service worker settings are null, do not even check if the API is available.
This commit is contained in:
parent
06ccf55454
commit
a463bb82c4
@ -72,8 +72,7 @@ _flutter.loader = null;
|
||||
*/
|
||||
constructor(validPatterns, policyName = "flutter-js") {
|
||||
const patterns = validPatterns || [
|
||||
/\.dart\.js$/,
|
||||
/^flutter_service_worker.js$/
|
||||
/\.js$/,
|
||||
];
|
||||
if (window.trustedTypes) {
|
||||
this.policy = trustedTypes.createPolicy(policyName, {
|
||||
@ -116,10 +115,19 @@ _flutter.loader = null;
|
||||
* @returns {Promise} that resolves when the latest serviceWorker is ready.
|
||||
*/
|
||||
loadServiceWorker(settings) {
|
||||
if (!("serviceWorker" in navigator) || settings == null) {
|
||||
if (settings == null) {
|
||||
// In the future, settings = null -> uninstall service worker?
|
||||
console.debug("Null serviceWorker configuration. Skipping.");
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (!("serviceWorker" in navigator)) {
|
||||
let errorMessage = "Service Worker API unavailable.";
|
||||
if (!window.isSecureContext) {
|
||||
errorMessage += "\nThe current context is NOT secure."
|
||||
errorMessage += "\nRead more: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts";
|
||||
}
|
||||
return Promise.reject(
|
||||
new Error("Service worker not supported (or configured).")
|
||||
new Error(errorMessage)
|
||||
);
|
||||
}
|
||||
const {
|
||||
|
||||
@ -881,6 +881,8 @@ void main() {
|
||||
flutter_js.generateFlutterJsFile(fileGeneratorsPath);
|
||||
expect(flutterJsContents, contains('"use strict";'));
|
||||
expect(flutterJsContents, contains('main.dart.js'));
|
||||
expect(flutterJsContents, contains('if (!("serviceWorker" in navigator))'));
|
||||
expect(flutterJsContents, contains(r'/\.js$/,'));
|
||||
expect(flutterJsContents, contains('flutter_service_worker.js?v='));
|
||||
expect(flutterJsContents, contains('document.createElement("script")'));
|
||||
expect(flutterJsContents, contains('"application/javascript"'));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user