Skip to content
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

Closed
3 tasks done
dfahlander opened this issue Feb 26, 2023 · 5 comments · Fixed by #37421
Closed
3 tasks done

[Bug]: BroadcastChannel support broken in version 23 #37417

dfahlander opened this issue Feb 26, 2023 · 5 comments · Fixed by #37421
Assignees
Labels
23-x-y 24-x-y bug 🪲 component/node-integration has-repro-gist Issue can be reproduced with code at https://gist.github.com/ status/confirmed A maintainer reproduced the bug or agreed with the feature

Comments

@dfahlander
Copy link

dfahlander commented Feb 26, 2023

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:

  1. Run it with Electron 22
  2. Move the browser window so you see the other browser window behind
  3. Click Post message button and see how messages arrive on the other window
  4. Run it with Electron 23
  5. Repeat step 2 and 3 but now messages aren't propagated to the other window.

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.

@github-actions
Copy link
Contributor

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 blocked/need-repro label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.

@dfahlander
Copy link
Author

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.

@github-actions github-actions bot removed the blocked/need-repro Needs a test case to reproduce the bug label Feb 27, 2023
@dfahlander
Copy link
Author

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.

@MarshallOfSound
Copy link
Member

I believe this is a bug in this PR --> nodejs/node#40532

Specifically the initialization of BroadcastChannel should not be done where it currently is (in bootstrap/node) and rather it should be moved to bootstrap/browser

cc @zcbenz @codebytere

@codebytere codebytere self-assigned this Feb 27, 2023
@codebytere codebytere added component/node-integration status/confirmed A maintainer reproduced the bug or agreed with the feature has-repro-gist Issue can be reproduced with code at https://gist.github.com/ labels Feb 27, 2023
@VerteDinde VerteDinde moved this from Unsorted Items to Fixed for Next Release in 24-x-y Mar 1, 2023
@serdaryesilmurat
Copy link

serdaryesilmurat commented Oct 2, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
23-x-y 24-x-y bug 🪲 component/node-integration has-repro-gist Issue can be reproduced with code at https://gist.github.com/ status/confirmed A maintainer reproduced the bug or agreed with the feature
Projects
No open projects
Status: Fixed for Next Release
Development

Successfully merging a pull request may close this issue.

5 participants