Skip to content
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

.Request is not a function in Cloudflare Workers #760

Closed
ben-xD opened this issue May 17, 2021 · 2 comments
Closed

.Request is not a function in Cloudflare Workers #760

ben-xD opened this issue May 17, 2021 · 2 comments

Comments

@ben-xD
Copy link

ben-xD commented May 17, 2021

When using Ably in Cloudflare Workers, the following errors are shown when Ably.Rest.auth.createTokenRequest or Ably.Rest.auth.requestToken is called. These don't happen in pure WebWorker environments and only in Cloudflare Workers. There was a separate issue for WebWorkers being resolved by this PR.

Screenshot 2021-05-17 at 10 37 40

The error seems to be caused by calling Http.Request in line 136 of browser/lib/util/https.js. However, why it only happens in Cloudflare Workers (and not Web Workers in general), I don't know. I personally am not blocked by this bug/ issue because I stopped using Cloudflare Workers because the debugging experience was not good. Firebase functions can be debugged with breakpoints in WebStorm, and it's been great. Though it might be good to support users who wish to use Ably on Cloudflare Workers.

Reproducing it

  • Create a free cloudflare account if you don't have one. You don't need to do anything else, you automatically get given a workers.dev domain: e.g. abcd.workers.dev. You can change it if you want.
  • Follow getting started guide from this repo.
  • Notice the error shown above in the terminal output

A small bit of detail about Cloudflare Workers

It configures webpack target to be webworker, but it also uses the Service Worker APIs to incept network requests/ act as a server/ serverless function. The reason they do this instead of running NodeJS is cost, performance and scalability. There is no cold start issue like normal serverless, much lower memory footprint. More about that here. So perhaps it is because we do not support running in "service worker", though this is just a guess.

┆Issue is synchronized with this Jira Uncategorised by Unito

@ben-xD ben-xD closed this as completed May 28, 2021
@ben-xD ben-xD reopened this May 28, 2021
@ben-xD
Copy link
Author

ben-xD commented May 28, 2021

The error can be reproduced here on the main branch. I've updated it to use Ably's webworker webpack output.

This is error is probably related to the other issue running in Cloudflare Workers: #766

@ben-xD
Copy link
Author

ben-xD commented May 29, 2021

I just got tokenRequests generated in Cloudflare workers, the code can be found here: https://github.com/ben-xD/ably-cloudflare-workers

So I am closing this. :)

@ben-xD ben-xD closed this as completed May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant