Replies: 3 comments 7 replies
-
https://developer.chrome.com/docs/extensions/reference/api/runtime#event-onMessage (message: any, sender: MessageSender, sendResponse: function) => boolean | undefined Please using // Example of a simple user data object
const user = {
username: 'demo-user'
};
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
// 2. A page requested user data, respond with a copy of `user`
if (message === 'get-user-data') {
sendResponse(user);
}
}); Note: Using |
Beta Was this translation helpful? Give feedback.
-
@aiktb I tried but it didn't work.
|
Beta Was this translation helpful? Give feedback.
-
@aiktb I succeeded, thank you very much. It turns out that changing the browser back to Chrome did the trick. But does this mean it's a bug in WXT? Is there a way to achieve this using WXT? |
Beta Was this translation helpful? Give feedback.
-
I tried to send a message from the background to the content script and get the result returned by the content script, but it always returns empty. However, I debugged in the content script and confirmed that there is data returned, so I'm not sure where I went wrong.
The following is my code
background.ts
content.ts
The return value of this.bufferQueue.shift() is not empty. The return value is a 2-dimensional array, but on the background side, the result is always null.
In addition, I configured the tabs permission in wxt.config.ts. May I ask where did I go wrong?
Beta Was this translation helpful? Give feedback.
All reactions