-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Support node env override in Electron renderer process #5577
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
Support node env override in Electron renderer process #5577
Conversation
I'm wondering if this issue is only happening to wasm file and not to mem file or other potential paths. Did you investigate it further? |
@nazar-pc Current stable electron supports native wasm, so I didn't verify asm.js or other paths at the moment I wrote this PR. |
Great! I think it should be fine then, wasm is the main focus for future development anyway. |
I just noticed some running context on Electron might need falls back to asm.js (like |
Well, if that is a real issue, I'd deal with it in the same PR just because it is essentially the same issue. Also I'm wondering why |
: it is not a bug (of Electron), there are discussions around CSP interaction in design WebAssembly/design#1092 , at this moment it simply falls back to not to allow compile wasm binary based on CSP . (i.e : https://bugs.chromium.org/p/chromium/issues/detail?id=686369). I haven't verified by myself, but just using |
Actually I'm more hoping #5296 could land instead of this PR, provides options does't require to deal with special running context checking. |
Instead of detecting electron, could we see if the |
@kripken I would say |
This is a use case for Electron only. If/when other environment like this exists, the issue will need to be fixed again, introducing even more workarounds.
I don't see any problem here. Look like no one expected |
While I said this is case for Electron, this is for any environment for where node.js has global
Following your comment, this means any further user environment have global |
In short, if this PR's not being accepted I agree with those decisions, but I'd argue |
I thought about this issue a bit more and end up with #5596. |
I just uploaded #5606 which may have some bearing on this too. I don't really understand from this thread what it is that prevents fetch from being used in electron, that wouldn't just affect the web in the same way? In any case, I suppose if it has fetch, Electron may end up with edit: I guess the real reason is that you are using a local FS through node.js, and while fetch may work, you'd just rather use the local FS instead? |
right; i guess my question is, do we need to do the same for #5606? |
I think so. If any branch's just execute based on existense of feature, it'll fall back same cases. |
Electron seems like an odd environment because it's not really purely |
Looks like #5606 will be the second place using
It is Node.js and Browser at the same time. Which means you can load WebAssembly from the local filesystem and using Web APIs like However, when you're loading a library from local filesystem and then trying to load WebAssembly for its consumption using |
Yes, that's reason #5606 accepts checker, cause |
Actually there are a few more places where |
We could have fetch be something overridable on the module too. (Either a function, or some value that indicates that fetch is available and desired). Are there other cases besides loading files where Electron has capabilities both of web and node? Should they be handled all with one big switch ("I always prefer node capabilities") or independently ("I want node FS instead of fetch, but everything else to be web")? |
Potentially there might be other cases, but I'd not overengineer it too early. Also |
So maybe some module-level fetch function or variable. Also I just discovered that |
Yeah, I think If it adds new capabilities, we could detect whether we can use it and use it in |
@kripken, that is a very good point! But I'd like to clarify that So my suggestion would be to switch over to using I can work on such PR if it sounds appropriate. |
I think moving all the logic into |
Agreed, let's move code into readAsync, and make that a promise. (I don't think we need to worry about changing an internal API like that.) |
It might not be legit approach to solve issues and possibly I am lack of way to correctly setting it - feel freely close PR if so.
This PR try to resolve usecases in Electron (https://electron.atom.io/) 's renderer process. Electron's renderer process is basically web browser instance but have node.js integration, so it is possible global context to have
window.fetch
and node.js both. In those process, setting upENVIRONMENT
toNODE
is not sufficient to load wasm binary without fetch, as current detection logic falls back to usefetch
as soon as it is available.Instead, adds one additional condition to check - if given process is Electron (where
window
have node.jsrequire
andfetch
both) but explicitly overridden to useNODE
, skips tofetch
. Otherwise it'll work as same as browser context.