Skip to content

Latest commit

 

History

History
87 lines (64 loc) · 3.21 KB

README.md

File metadata and controls

87 lines (64 loc) · 3.21 KB

webpush - Web Push library for Deno and other web compatible runtime.

jsr badge license MIT badge code size badge

webpush is a Web Push library (RFC 8291 and RFC 8292) based on Web APIs.

NOTE: This library hasn't been reviewed by crypto experts and may be unsecure. I've done my best to follow RFC recommandation and I only used primitives provided by the SubtleCrypto API.

webpush is available on JSR.

Getting started

Before sending Web Push message to a user agent, you need to create VAPID keys (see RFC 8292) to identify your server (Application) to the Push Service:

+-------+           +--------------+       +-------------+
|  UA   |           | Push Service |       | Application |
+-------+           +--------------+       +-------------+
    |                      |                      |
    |        Setup         |                      |
    |<====================>|                      |
    |           Provide Subscription              |
    |-------------------------------------------->|
    |                      |                      |
    :                      :                      :
    |                      |     Push Message     |
    |    Push Message      |<---------------------|
    |<---------------------|                      |
    |                      |                      |

Run generate-vapid-keys script part of this repository to generate new keys:

# You can use any Web compatible runtime.
$ deno run https://raw.githubusercontent.com/negrel/webpush/master/cmd/generate-vapid-keys.ts

Copy the output of the command and save it in example/vapid.json. Now you can run example server.

$ cd example/
$ deno run -A ./main.ts

Code is commented be sure to read it.

I also wrote an ok-ish blog post about Web Push and this library.

Dependencies

This library tries its best at keeping the minimum number of dependencies. It has no external dependencies except some runtime agnostic @std/ packages maintained by Deno team and http-ece, which I maintain.

http-ece also only depends on @std/ packages.

Contributing

If you want to contribute to webpush to add a feature or improve the code contact me at alexandre@negrel.dev, open an issue or make a pull request.

🌠 Show your support

Please give a ⭐ if this project helped you!

buy me a coffee

📜 License

MIT © Alexandre Negrel