player.js icon indicating copy to clipboard operation
player.js copied to clipboard

Fails to detect Cloudflare Worker environments (issue with isNode)

Open davedbase opened this issue 4 years ago • 2 comments

Expected Behavior

Be able to deploy to Cloudflare Worker without environment error warning.

Actual Behavior

In deploy to the Cloudflare Worker, as the script initializes and prepares to go live, the Wrangler CLI throws an error:

🌀  Running 
✨  Build completed successfully!
🌀  Using namespace for Workers Site "__stage-site-workers_sites_assets"
✨  Success
🌀  Uploading site files
Error: Something went wrong with the request to Cloudflare...
Uncaught Error: Sorry, the Vimeo Player API is not available in this browser.
  at line 911
 [API code: 10021]

This is likely due to the fact that a Cloudflare Worker is not a node environment. The current detection method for a Node environment fails in this case and incorrectly blocks the deployment. To temporarily deploy I managed to uncomment the following at the bottom of player.js

if (!isNode) {
  // screenfull = initializeScreenfull();
  // initializeEmbeds();
  // resizeEmbeds();
}

Steps to Reproduce

Import player into an SSR script with import Player from "@vimeo/player"; then attempt a deployment to a live worker.

Possible solutions

I've been looking for a way to detect a CF environment since it's different than Node. I'm thinking that isNode could likely be extended to include this check. I've opened a thread within the CF community asking what an appropriate solution might be: https://community.cloudflare.com/t/how-to-detect-the-cloudflare-worker-runtime/293715

If anyone else has stumbled on this issue or is familiar with CF Workers, please weight in. I'd be happy to make a PR once this is known + tested.

davedbase avatar Aug 10 '21 22:08 davedbase

According to a response on the CF community forum we can identify CFW runtime by checking for: caches.default or WebSocketPair. I could submit a PR to account for this if there's a chance it would be accepted.

davedbase avatar Aug 12 '21 15:08 davedbase