-
Notifications
You must be signed in to change notification settings - Fork 15.7k
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]: BroadcastChannel support broken in version 23 #37417
Comments
Hello @dfahlander. Thanks for reporting this and helping to make Electron better! Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use. Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests. Now adding the |
Hi! I created a gist and updated the description. In the repro, I found that the issue only occurs when using contextIsolation: false on the browser windows. Still, I believe that should not affect the behavior of BroadcastChannel since it works perfectly well in Electron 22 but not Electron 23. See repro instructions. |
Hi again! Here comes my thoughts regarding the issue, if they could be beneficial somehow. The repro gist I posted verifies that this is an issue when using contextIsolation: false. I assume the issue could also occur in the preload.js script no matter contextIsolation. I suppose the problem is that the DOM version of BroadcastChannel is replaced by the Node version (since they share the exact same name) and that the Node version regards the different BrowserWindows as being the "same client" and therefore not propagate between them (I suppose the node version only propagates between different threads). An easy solution (I suppose) would be to prioritize the DOM version before the Node version of BroadcastChannel in both preload scripts and ordinary JS in contextIsolation: false. A perfect solution would probably be that the Node and the browser versions of BroadcastChannel where connected somehow and possible to use as the channel to communicate also between browser and main thread (as its intention would be). If so, maybe replace BroadcastChannel with your own implemention that would propagate and listen to both the DOM and the Node version. BroadcastChannel has a really tiny API surface so I suppose the implementation of such a connecting layer would be minimal. |
I believe this is a bug in this PR --> nodejs/node#40532 Specifically the initialization of |
Related issue: /~https://github.com/electron/electron/issues/40060 |
Preflight Checklist
Electron Version
23.1.1
What operating system are you using?
macOS
Operating System Version
Montery 12.6.3
What arch are you using?
x64
Last Known Working Electron version
22.3.1. Stops working in 23.0.0.
Expected Behavior
Setting up a new BroadcastChannel() in two BrowserWindows with
{ contextIsolation: false }
shall work and communicated events to each other.Actual Behavior
BrowserChannels do not communicate between BrowserWindows when contextIsolation is false.
Testcase Gist URL
Repro
Notes to repro:
Additional Information
It seems as the BroadcastChannel we see in a window, is the NodeJS version of BroadcastChannel and not the DOM version because it has the
unref()
method that is unique to Node's version. I don't know if this could be the reason why it does not work as in Electron version 22, where BroadcastChannel is absent in the node thread but present and working fine within BrowserWindows.The text was updated successfully, but these errors were encountered: