-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Loading sea.js with importScripts fails in worker #1334
Comments
https://github.com/amark/gun/blob/master/gun.js#L544 should only do if window exists, idk why its doing it without. but maybe the issue is we CANNOT do ES6+ module export because you can't try/catch and without it breaks old browsers. so maybe we can do something like |
I think the global is called WorkerGlobalScope or something stupid |
@amark Yes, if the first line is removed ( |
@amark what old browsers are you trying to support? To not have ES6 support, you would need to be using a 5+ year old browser. That is so old, it would be trivial to hack. According to caniuse, ~98.5%* of all network traffic supports ES6, and when you factor in that GUN already uses some methods that are not supported in old browsers, it is likely only a very small set of browsers that would see new breakage. If any developer has a need to support these old browsers, it is relatively simple to install Babel and transpile it to ancient JS. You could even do the transpiling in this repo and provide a simple code example showing how to conditionally load the transpiled vs new version of GUN. *: adjusting for known issues with caniuse's data |
@atjn There's also a question of if it would be better to use polyfills to regain the support of older browsers. On the topic of the thread. @eternal-turtles If you're attempting to use GUN within a web worker you may run into additional problems. AFAIK you cannot open a webRTC connection within a web worker and I believe GUNDB does require webrtc. Do watch my words though because in the link I call out it is mentioned that you can transfer an existing webrtc connection to a web worker. Will that work with GUN? Who knows! @amark might have an answer but experimentation may give us all more information. |
We found that adding the following at the top of the worker script is sufficient for importing gun/gun and gun/sea: |
Closing this issue since |
Hi, I'm seeing the following error when attempting to load sea.js using
importScripts
in a SharedWorker:In addition, it seems that loading gun.js using importScripts assigns GUN to
window
, which is unavailable in a worker environment. Is there a non-hacky way to load gun.js using importScripts?Code:
Demo: https://github.com/eternal-turtles/gun-shared-worker-bug-demo
The text was updated successfully, but these errors were encountered: