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

feat: support for messaging from main world content scripts #812

Merged
merged 3 commits into from
Nov 10, 2023

Conversation

edtervit
Copy link
Contributor

@edtervit edtervit commented Nov 9, 2023

Details

This PR ...

Allows usage of the message API when the content script is in the main world.

To send messages from content scripts in the main world chrome requires the following:

  • The extension's id to be passed as a string to sendMessage()
  • The service worker's listener to use onMessageExternal() instead of onMessage()

Read details from chrome here

I also submitted a PR to the docs that explains this change

This is my first proper PR to open source so please be kind ❤️

Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I agree to license this contribution under the MIT LICENSE
  • I checked the current PR for duplication.

@louisgv
Copy link
Contributor

louisgv commented Nov 10, 2023

@edtervit thank you for the PR :) - Are we sure that by passing null to the first argument, it would behave the same as without it?? I'm surprised this is the behavior lol!

@louisgv
Copy link
Contributor

louisgv commented Nov 10, 2023

Holy cow you're right - I've never seen a pattern where the 1st argument is optional lol....

Copy link
Contributor

@louisgv louisgv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 - note that this is a substantial API behavior change.

If the user doesn't need to use external message, it would duplicate the generated code. However, it's prob not a huge deal since the switch statement is pretty compact anyway.

@louisgv louisgv added this pull request to the merge queue Nov 10, 2023
Merged via the queue into PlasmoHQ:main with commit 11ded48 Nov 10, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants