summaryrefslogtreecommitdiffstats
path: root/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html')
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html
new file mode 100644
index 000000000..fc3d9ded4
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/sw.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <script>
+ function logState(state) {
+ console.log("Service worker " + state)
+ }
+
+ const registerServiceWorker = async () => {
+ try {
+ var serviceWorker;
+ const registration = await navigator.serviceWorker.register('/sw.js');
+ if (registration.installing) {
+ serviceWorker = registration.installing;
+ } else if (registration.waiting) {
+ serviceWorker = registration.waiting;
+ } else if (registration.active) {
+ serviceWorker = registration.active;
+ }
+ } catch (error) {
+ console.error("Service worker registration error: ${error}");
+ }
+ if (serviceWorker) {
+ logState(serviceWorker.state);
+ serviceWorker.addEventListener('statechange', function(e) {
+ logState(e.target.state);
+ });
+ }
+ };
+ if ('serviceWorker' in navigator) {
+ registerServiceWorker();
+ navigator.serviceWorker.ready.then((registration) => {
+ navigator.serviceWorker.onmessage = (event) => {
+ if (event.data && event.data.type === 'PONG') {
+ console.log("Service worker done");
+ }
+ };
+ registration.active.postMessage({type: 'PING'});
+ });
+ }
+ </script>
+ </body>
+</html>