-
Notifications
You must be signed in to change notification settings - Fork 15k
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
[Bug]: registerStreamProtocol does not work with native fetch Response.body #37285
Comments
I'm not sure this is necessarily a bug, more confusing due to Node.js changes. Historically Node.js only had It looks like the Node.js docs now refer to const { PassThrough, Readable } = require('stream')
[...]
data: Readable.fromWeb(response.body) |
Indeed, that is confusing (if you also throw I don't think Electron needs to necessarily transparently handle this for me. Maybe this has now turned into a feature request for:
|
This is an interesting case but I'd make the IMO compelling case for Electron to disable / replace the global fetch in the main process with either our own implementation --> #36733 or by just removing it from the global scope. It has a giant footgun in that it uses Node's network stack instead of Chromiums which means requests don't route through cc @nornagon Thoughts on using |
This goes both ways. "Replacing
It will probably break npm packages that build on global fetch, increasing the gap between Electron and Node.js. I was hoping the list of differences would shrink, not increase. In the context of In any case, if you go down the route of replacing it please give us sth. like the There could also be a flag to re-enable native Also what about Worker threads? Right now I treat my server worker like any Node.js app (and Workers do behave different than the main process). Would you also replace |
Just to be super clear, my comment was spitballing. Not a recommended course of action. The point I was trying to make was We could also leave it alone but IMO that's not viable, random node modules will use
Details? I'm not aware of such usecases |
Thanks for clarifying.
Could you point to documentation about this? I don't understand why I would want that? But if that's something that needs to be done for some technical reason then I'd love to know about this.
I've never though about it in detail, but for me Electron is a client server architecture. And my server is a literal web server running in a worker thread that serves the content for the renderer. As such it doesn't make sense to use Chromium's network stack (for requests I make within the server to the internet) since this is a Node.js application. I also don't know enough about Chromium's network stack to "trust" it. It's a magic black box optimized for web browsing whereas I've been working with the Node.js network stack for over ten years. For example I don't know if Chromium's network stack would transparently handle cookies for me or if it would cache things. And I don't feel like digging into these things since I know that the Node.js stack won't do anything like that without my consent. Chromium's network stack also has limitations (coming from the fact that it is made for web browsing) such as not having full control over all headers. Also isn't it limited to HTTP(S) only? How would I do anything else with it's network stack? If my renderer needs to use a proxy and do other web browser related things, then I don't see how this has anything to do with my server needing a proxy. These are completely separate concerns? |
I think this is a bad idea and we shouldn't do it. There are good reasons for apps to want to use Node's networking stack, and it would be surprising for As for this bug/feature request, I have plans to significantly improve the |
Preflight Checklist
Electron Version
23.0.0
What operating system are you using?
Ubuntu
Operating System Version
Linux alex-NUC11PAHi7 5.19.0-31-generic #32-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan 20 15:20:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
What arch are you using?
x64
Last Known Working Electron version
N/A
Expected Behavior
Returning
Response.body
of the nativefetch
API fromregisterStreamProtocol
should stream the thingActual Behavior
Apparently
Response.body
of thefetch
API is supposed to be aReadableStream
. But returning it fromregisterStreamProtocol
does not work (ERR_FAILED).Testcase Gist URL
https://gist.github.com/5ba47c8cd5e44d19bb97bb2100b32983
Additional Information
The Fiddle is based on the original example from the docs https://www.electronjs.org/docs/latest/api/protocol#protocolregisterstreamprotocolscheme-handler
Commenting out the line and using
data: createStream('<h5>Response</h5>')
streams the things.Maybe a better error message than
ERR_FAILED
would also be noice.The text was updated successfully, but these errors were encountered: