plasmo icon indicating copy to clipboard operation
plasmo copied to clipboard

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

Open nikolalukovic opened this issue 1 year ago • 7 comments

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

  • [ ] I would like to fix this BUG via a PR

Code of Conduct

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

nikolalukovic avatar Nov 17 '23 10:11 nikolalukovic

Error: Extension runtime is not available

Ad312Cody avatar Nov 27 '23 03:11 Ad312Cody

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.

ocersnguyend avatar Jan 16 '24 18:01 ocersnguyend

Same for me

veedeo avatar Feb 17 '24 20:02 veedeo

@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.

jahilliard avatar May 30 '24 04:05 jahilliard

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.

naan avatar May 30 '24 10:05 naan

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.

jahilliard avatar May 30 '24 17:05 jahilliard

Same for me image

liangkuku avatar Jul 06 '24 12:07 liangkuku