File tree Expand file tree Collapse file tree 1 file changed +2
-21
lines changed Expand file tree Collapse file tree 1 file changed +2
-21
lines changed Original file line number Diff line number Diff line change @@ -60,32 +60,13 @@ webpush.sendNotification(pushSubscription, 'Your Push Payload Text');
6060
6161## Using VAPID Key for applicationServerKey
6262
63- When using your VAPID key in your web app, you'll need to convert the
64- URL safe base64 string to a Uint8Array to pass into the subscribe call,
63+ When subscribing to push messages, you'll need to pass your VAPID key,
6564which you can do like so:
6665
6766``` javascript
68- function urlBase64ToUint8Array (base64String ) {
69- const padding = ' =' .repeat ((4 - base64String .length % 4 ) % 4 );
70- const base64 = (base64String + padding)
71- .replace (/ -/ g , ' +' )
72- .replace (/ _/ g , ' /' );
73-
74- const rawData = window .atob (base64);
75- const outputArray = new Uint8Array (rawData .length );
76-
77- for (let i = 0 ; i < rawData .length ; ++ i) {
78- outputArray[i] = rawData .charCodeAt (i);
79- }
80- return outputArray;
81- }
82-
83- const vapidPublicKey = ' <Your Public Key from generateVAPIDKeys()>' ;
84- const convertedVapidKey = urlBase64ToUint8Array (vapidPublicKey);
85-
8667registration .pushManager .subscribe ({
8768 userVisibleOnly: true ,
88- applicationServerKey: convertedVapidKey
69+ applicationServerKey: ' <Your Public Key from generateVAPIDKeys()> '
8970});
9071```
9172
You can’t perform that action at this time.
0 commit comments