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

Can not get responses in Popup script #1331

Open
5 tasks done
pangmaowang opened this issue Jan 4, 2025 · 3 comments
Open
5 tasks done

Can not get responses in Popup script #1331

pangmaowang opened this issue Jan 4, 2025 · 3 comments
Labels
question A question about usage, not a bug

Comments

@pangmaowang
Copy link

Describe the bug

Hi, I am new to extension dev, I am following the examples in background forward message, but the popup can not get the message, I am bit confused what's happening here.

Based on the code, I am expecting it should receive a response and display it, but the response is actually undefined here.
image
I tried the suggestion here but it is still not working..
#971

Reproduction

https://github.com/wxt-dev/examples/tree/main/examples/background-message-forwarder

Steps to reproduce

run the example, see if you could get the response displayed

System Info

System:
    OS: macOS 15.2
    CPU: (10) arm64 Apple M4
    Memory: 319.52 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
    pnpm: 8.6.2 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 131.0.6778.205
    Safari: 18.2

Used Package Manager

npm

Validations

@pangmaowang pangmaowang added the pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug label Jan 4, 2025
@pangmaowang
Copy link
Author

pangmaowang commented Jan 4, 2025

Finally got it working after debugging for the whole afternoon..
It seems the example no longer works the way it’s written—correct me if I’m wrong.
Chrome requires a synchronous return of true or false:
false: The channel closes immediately (suitable for synchronous code).
true: The channel remains open (suitable for asynchronous code).
Workaround:
Instead of making the listener async, we can return true to keep the channel open and then handle the async logic in a separate async function.
image

@aklinker1
Copy link
Collaborator

If you're using extensionApi: "chrome", you'll need to use a synchronous callback, return true, and use sendResponse as you described. The example should work just fine since it uses the webextension-polyfill, but it should be updated so it works with both APIs using sendResponse, especially since v0.20 will be changing the default.

@aklinker1 aklinker1 added question A question about usage, not a bug and removed pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug labels Jan 4, 2025
@pangmaowang
Copy link
Author

Thanks for the detailed explanation! I didn’t realize it was the config extension difference that caused it to stop working.

It’s great to learn something new about extension development—really appreciate your insights

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about usage, not a bug
Projects
None yet
Development

No branches or pull requests

2 participants