This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[web] Fix JS crash when FF blocks service workers. (#106072)
- Loading branch information
Showing
5 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
dev/integration_tests/web/lib/service_worker_test_blocked_service_workers.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:html' as html; | ||
Future<void> main() async { | ||
const String response = 'CLOSE?version=1'; | ||
await html.HttpRequest.getString(response); | ||
html.document.body?.appendHtml(response); | ||
} |
48 changes: 48 additions & 0 deletions
48
dev/integration_tests/web/web/index_with_blocked_service_workers.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE HTML> | ||
<!-- Copyright 2014 The Flutter Authors. All rights reserved. | ||
Use of this source code is governed by a BSD-style license that can be | ||
found in the LICENSE file. --> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta content="IE=Edge" http-equiv="X-UA-Compatible"> | ||
|
||
<title>Web Test</title> | ||
<!-- iOS meta tags & icons --> | ||
<meta name="apple-mobile-web-app-capable" content="yes"> | ||
<meta name="apple-mobile-web-app-status-bar-style" content="black"> | ||
<meta name="apple-mobile-web-app-title" content="Web Test"> | ||
<link rel="manifest" href="manifest.json"> | ||
|
||
<script> | ||
// This is to break the serviceWorker registration, and make it throw a DOMException! | ||
// Test for issue https://github.com/flutter/flutter/issues/103972 | ||
window.navigator.serviceWorker.register = (url) => { | ||
console.error('Failed to register/update a ServiceWorker for scope ', url, | ||
': Storage access is restricted in this context due to user settings or private browsing mode.'); | ||
return Promise.reject(new DOMException('The operation is insecure.')); | ||
} | ||
</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> | ||
</head> | ||
<body> | ||
<script> | ||
window.addEventListener('load', function(ev) { | ||
// Download main.dart.js | ||
_flutter.loader.loadEntrypoint({ | ||
serviceWorker: { | ||
serviceWorkerVersion: serviceWorkerVersion, | ||
} | ||
}).then(function(engineInitializer) { | ||
return engineInitializer.autoStart(); | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters