Skip to content

Bun BroadcastChannel never receive for same reference #10433

Closed

Description

@ellemedit

What version of Bun is running?

1.1.4

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

import { test, expect } from "bun:test";

test("broadcast channel", async () => {
  const bc = new BroadcastChannel("test");
  const resolver = Promise.withResolvers();
  bc.onmessage = (event) => {
    console.log(event);
    resolver.resolve();
  };
  bc.postMessage({ test: true });
  await resolver.promise;
});

never pass

What is the expected behavior?

It should be passed

What do you see instead?

No response

Additional information

No response

Activity

  1. added
    web-apiSomething that relates to a standard Web API
    on Apr 22, 2024
  2. redjohnsh commented on Sep 21, 2024

    @redjohnsh

    Any news on this?

  3. Ristovski commented on Sep 21, 2024

    @Ristovski
    import { expect, test } from "bun:test";
    
    test("broadcastChannel", async () => {
        const message = "test";
    
        const sender = new BroadcastChannel("test");
        const receiver = new BroadcastChannel("test");
    
        let receivedMessage = null;
    
        receiver.onmessage = (message) => {
            receivedMessage = message;
        };
    
        sender.postMessage(message);
    
        expect(receivedMessage).toBe(null);
    
        await new Promise((resolve) => {
            setTimeout(() => {
                resolve(null);
            }, 0);
        });
    
        expect(receivedMessage.data).toBe(message);
    
        sender.close();
        receiver.close();
    });
    bun test v1.1.25-canary.29 (63596c3f)
    
    test.js:
    ✓ broadcastChannel [2.00ms]
    
     1 pass
     0 fail
     2 expect() calls
    Ran 1 tests across 1 files. [8.00ms]
    

    Note the expect(receivedMessage).toBe(null); followed by the resolve.

  4. alii commented on May 13, 2026

    @alii
    Member

    Couldn't reproduce this on Bun 1.3.13 (linux x64). Closing — if you're still hitting it on the latest release, please drop a fresh repro and we'll reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingweb-apiSomething that relates to a standard Web API

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions