Skip to content

[BUG] Plasmo Messaging completely breaking in Chrome 144+ #1341

@TejeshJadhav-cactus

Description

@TejeshJadhav-cactus

What happened?

Firstly, I note that some messaging documentation DOES call out Chrome 144 changes: https://developer.chrome.com/docs/extensions/develop/concepts/messaging. Though, notably, the runtime reference API documentation does not include this information.

Previous behavior in < 144:
onMessage listeners could return an explicit true to indicate that a listener intends to respond to the message asynchronously via the sendResponse callback. Any other return value was ignored.

Behavior in >= 144:
onMessage listeners can still return an explicit true and asynchronously respond via sendResponse. NEW BEHAVIOR: alternatively, onMessage listeners can return a Promise to respond asynchronously - the promise's resolution is the response.

A gotcha (what broke my company's extension):
tl;dr One of our onMessage listeners was an async function that wasn't intending to send a response.

The first onMessage listener to respond is what is sent to the caller. We have multiple onMessage listeners in disparate parts of our codebase. Each of these listeners ignore messages that are unrelated to that particular listener; they would simply return [void] for messages they didn't care about.

However in one instance, for syntactic convenience, a listener was an async function, i.e. returned aPromise.
In <144, this works fine. Because the return value isn't an explicit true, Chrome doesn't expect an asychronous response.
In >=144, Chrome interprets a Promise as intending to respond.

Our async function watered-down:

async function listener(msg) {
if (msg.type !== 'myMessageType') {
return // ignore this message, not the message I'm looking for
}

// do other async stuff
}
This listener fires on every message, obviously. So for messages it originally ignored, it is immediately returning a resolved Promise resulting in Chrome sending an incorrect null back to our callers.

Version

Latest

What OS are you seeing the problem on?

No response

What browsers are you seeing the problem on?

Chrome

Relevant log output

(OPTIONAL) Contribution

  • I would like to fix this BUG via a PR

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I checked the current issues for duplicate problems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions