WebPushClient

push. WebPushClient

Send a Web push notification using the web-push npm module, referer to it for details how to generate VAPID credentials to configure this module with 3 required parameters:

Config must have this entry for worker to work:

api-headers-^/js/webpush.js = { "Service-Worker-Allowed": "/" }

The device token must be generated in the browser after successful subscription:

Constructor

new WebPushClient(options)

Source:
Parameters:
Name Type Description
options object | Array.<object>
Properties
Name Type Description
key string

VAPID private key

pubkey string

VAPID public key

email string

an admin email for the VAPID subject

Example
const registration = await navigator.serviceWorker.register("/js/webpush.js", { scope: "/" });
const subscription = await registration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: vapidKeyPublic });
app.fetch('/user/update', { data: { pushkey: "webpush://" + window.btoa(JSON.stringify(subscription)) }, type: "POST" });