зеркало из https://github.com/openwpm/OpenWPM.git
46 строки
1.4 KiB
HTML
46 строки
1.4 KiB
HTML
<html>
|
|
<head>
|
|
<title>HTTP Test page including a service worker</title>
|
|
<link rel='icon' href='shared/test_favicon.ico' />
|
|
</head>
|
|
<body>
|
|
<p> This test page registers a service worker, then sends a message
|
|
to the worker to tell it to make a request.
|
|
</p>
|
|
<script>
|
|
if ('serviceWorker' in navigator) {
|
|
navigator.serviceWorker.register(
|
|
'./shared/service_worker.js',
|
|
{scope: './shared/'}
|
|
).then((reg) => {
|
|
// registration worked
|
|
console.log('Registration succeeded. Scope is ' + reg.scope);
|
|
var serviceWorker;
|
|
if (reg.installing) {
|
|
serviceWorker = reg.installing;
|
|
} else if (reg.waiting) {
|
|
serviceWorker = reg.waiting;
|
|
} else if (reg.active) {
|
|
serviceWorker = reg.active;
|
|
}
|
|
serviceWorker.addEventListener('statechange', (e) => {
|
|
// Send message to service worker to trigger image load.
|
|
if (e.target.state === 'activated') {
|
|
reg.active.postMessage("Fetch image.");
|
|
}
|
|
})
|
|
}).catch((error) => {
|
|
// registration failed
|
|
console.log('Registration failed with ' + error);
|
|
});
|
|
}
|
|
</script>
|
|
<script>
|
|
var request = new Request(
|
|
'http://localhost:8000/test_pages/shared/test_image.png'
|
|
);
|
|
fetch(request);
|
|
</script>
|
|
</body>
|
|
</html>
|