|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Game Site</title>
|
|
<script>
|
|
this.onpush = (event) => {
|
|
console.log(event.data);
|
|
// From here we can write the data to IndexedDB, send it to any open
|
|
// windows, display a notification, etc.
|
|
};
|
|
|
|
navigator.serviceWorker
|
|
.register("service-worker.js")
|
|
.then((serviceWorkerRegistration) => {
|
|
serviceWorkerRegistration.pushManager.subscribe().then(
|
|
(pushSubscription) => {
|
|
const subscriptionObject = {
|
|
endpoint: pushSubscription.endpoint,
|
|
keys: {
|
|
p256dh: pushSubscription.getKey('p256dh'),
|
|
auth: pushSubscription.getKey('auth'),
|
|
},
|
|
encoding: PushManager.supportedContentEncodings,
|
|
/* other app-specific data, such as user identity */
|
|
};
|
|
console.log(pushSubscription.endpoint, pushSubscription, subscriptionObject);
|
|
// The push subscription details needed by the application
|
|
// server are now available, and can be sent to it using,
|
|
// for example, the fetch() API.
|
|
},
|
|
(error) => {
|
|
console.error(error);
|
|
},
|
|
);
|
|
});
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
</body>
|
|
</html> |