PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
8.84k stars 314 forks source link

[BUG] The content script cannot send message to the background script when the world is set to "MAIN". #1019

Closed parametprame closed 3 hours ago

parametprame commented 3 days ago

What happened?

sendToBackground in the content script doesn't work when I config it like this.

const config: PlasmoCSConfig = { matches: ["<all_urls>"], world: "MAIN", run_at: "document_start" }

Version

Latest

What OS are you seeing the problem on?

MacOSX

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

(OPTIONAL) Contribution

Code of Conduct

parametprame commented 3 hours ago

To fix the bug, you can follow the example provided in the https://github.com/PlasmoHQ/examples/tree/main/with-messaging. This example demonstrates how to send a message from a content script to a background script.