When sidePanel is opened, async handlers in the background stop working

125 views
Skip to first unread message

Oriol Grau Perejoan

unread,
Jul 15, 2025, 11:59:09 AM7/15/25
to Chromium Extensions
Hi everyone,

I'm developing a v3 chrome extension, and facing the following issue: 

When the sidePanel is opened, any async handler in the background that is triggered by the content script via `chrome.runtime.sendMessage` is resolved synchronously and returning null. I can see that the messages are received and processed by the background, but the responses are sent back to the content script before the async callbacks resolve.

When the sidePanel is closed, everything was and is working fine.

I’m following best practices I found in the documentation and in discussions in this group, such as registering listeners at the top level

```
chrome.runtime.onMessage.addListener(onMessageHandler);
```

or returning true in callbacks:

```
const onMessageHandler = (
  message: Message,
  sender: chrome.runtime.MessageSender,
  sendMessage: (result: any) => void
) => {
  (async () => {
    switch (message.action) {
      case 'message': {
        const response = await fetchWhatever();
        sendMessage(response);
        break;
      }
    }
  })();

  return true;
};
```

Also, I found that this issue is completely fixed if I use long-lived messages

Has anyone faced similar issues? 
Does anyone know what causes this behavior? 
Am I doing something wrong?
Thanks in advance!

Oriol



Rajat Paharia

unread,
Jul 22, 2025, 1:10:48 PM7/22/25
to Chromium Extensions, Oriol Grau Perejoan
Based on the symptoms that you're describing, my best guess would be that you also have a message handler in your sidepanel code that is listening for "message" and that it is responding first. 

- rajat

Reply all
Reply to author
Forward
0 new messages