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:

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" });