Skip to content

πŸ”‘ Convert a VAPID public key to an Uint8Array

License

Notifications You must be signed in to change notification settings

screendriver/convert-vapid-public-key

Folders and files

NameName
Last commit message
Last commit date
Oct 23, 2023
Oct 9, 2022
Jul 13, 2023
Jul 16, 2023
Oct 9, 2022
Jul 13, 2023
Aug 29, 2019
May 27, 2020
Oct 9, 2022
Jul 16, 2023
Sep 20, 2023
Jul 16, 2023
Nov 14, 2018
Sep 20, 2023
Jul 17, 2023
Mar 25, 2025
Mar 25, 2025
Jul 16, 2023
Oct 9, 2022

Repository files navigation

convert-vapid-public-key

GitHub Actions status

To subscribe to Web Push Notifications you have to provide an Base64 application server key that needs to be converted to an Uint8Array. This package helps you with the conversion from a Base64 string to an Uint8Array.

Installation πŸ—

$ npm install --save convert-vapid-public-key

or if you use Yarn 🐈

$ yarn add convert-vapid-public-key

Usage πŸ”¨

import convertVapidKey from "convert-vapid-public-key";

async function subscribe() {
	const registration = await navigator.serviceWorker.register("service-worker.js");
	const subscribeOptions = {
		userVisibleOnly: true,
		applicationServerKey: convertVapidKey("<your-base64-vapid-public-key>"),
	};
	const pushSubscription = await registration.pushManager.subscribe(subscribeOptions);
	// ...
}