-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloudflare Worker support? #718
Comments
ECDH is not supported by https://developers.cloudflare.com/workers/runtime-apis/web-crypto so it would have to be manually implemented. |
This pkg: https://github.com/alastaircoote/webpush-webcrypto is NodeJS dependency free of any node core modules and uses web crypto instead 👍 |
Edit: Tried again today (12-23-2023) and now Original:Unfortunately, https://github.com/alastaircoote/webpush-webcrypto didn't quite work. I got it working locally with wrangler2 in local mode (which tries to emulate the real environment). However, when I actually tried it on Cloudflare, it doesn't get past I did notice this repo, which appears to have successfully implemented ~webpush on Cloudflare: |
Setup
Currently web-push does not work on Cloudflare Workers. These do not use Node, so certain libraries are not available. They do offer a new Node compatibility mode, but it does not resolve all issues.
Operating System: Cloudflare Worker
Node Version: none
web-push Version: 3.5.0
Problem
I am trying to send a notification on a Cloudflare Worker using the usual two lines of code mentioned below. These do work when running under Node. But not on Cloudflare.
Expected
Would be nice if web-push would support sending notifications when running on a Cloudflare Worker.
Features Used
webpush.setVapidDetails(...)
webpush.sendNotification(...)
Example / Reproduce Case
Set up a Cloudflare Worker by using Wrangler2. Then use the usual two lines of code above to try to send an notification.
It first ran into Buffers not being supported on Cloudflare. I was able to bypass this issue by enabling Cloudflare's Node compatibility mode for my Worker.
Next,
https.request
is not supported on Cloudflare. It instead requires use offetch
. I was able to resolve this issue by hand by replacing this code:web-push/src/web-push-lib.js
Line 338 in 0c5c44c
with this:
Unfortunately, that's when I ran into an issue I don't know how to resolve:
Other
While Cloudflare does not have node's crypto library, it does have this:
https://developers.cloudflare.com/workers/runtime-apis/web-crypto
I'm just not sure how to use this to accomplish what web-push is currently doing here:
web-push/src/encryption-helper.js
Line 41 in 5388395
The text was updated successfully, but these errors were encountered: