PlasmoHQ / plasmo

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

[BUG] Example code in documentation throws an error. Sending a message from MAIN world CS to Background. #823

Open nikolalukovic opened 10 months ago

nikolalukovic commented 10 months ago

What happened?

Docs example of sending a message from MAIN world CS to background throws an error. When trying to send a message to background thread from MAIN world CS I get this error:

Error: Extension runtime is not available

Specifically this example in docs: https://docs.plasmo.com/framework/messaging#:~:text=contents/componentInTheMainWorld.tsx

Version

Latest

What OS are you seeing the problem on?

Windows

What browsers are you seeing the problem on?

Chrome, Microsoft Edge

Relevant log output

No response

(OPTIONAL) Contribution

Code of Conduct

Ad312Cody commented 9 months ago

Error: Extension runtime is not available

ocersnguyend commented 8 months ago

Any update on this issue? Thank you! After trying all sort of ways, I find that the world: "MAIN" is causing the issue for me. When I removed this from the PlasmoCSConfig the issue went away.

veedeo commented 7 months ago

Same for me

jahilliard commented 3 months ago

@louisgv If this is called out as explicitly possible in the documentation, but doesn't work or is broken. FWIW, It's broken for me too. It seems like an easy fix to remove the example.

Awesome Framework btw.

naan commented 3 months ago

I don't think this feature ever worked. As the error said, extension runtime is not available in the Main World. Either the document should be removed, or rewrite to suggest using sendToBackgroundViaRelay.

jahilliard commented 3 months ago

For posterity, the work around is to put the data in the DOM somewhere so that it can be accessed from both a main and isolated world. It can then be sent to the background from the isolated world script. It's a pain to implement, but it works.

liangkuku commented 2 months ago

Same for me image