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

Add GM_messageExtension allowing userscript to trigger other WebExtension in FireMonkey #644

Open
GHolk opened this issue Jul 21, 2024 · 3 comments
Labels

Comments

@GHolk
Copy link

GHolk commented Jul 21, 2024

Hey, I'm a ViolentMonkey user, and I'm suggesting a new API GM_messageExtension,
which wrap the browser.runtime.sendMessage for userscript,
so they can send message to other extensions.

(Few people know that pass other extension's id as first argument
to browser.runtime.sendMessage will send message to other extension's onMessageExternal handler.)

API design

  • The userscript have to @grant GM_messageExtension.
  • The userscript have to declare the extension id they want to connect with
    @connect web-extension://[email protected] or web-extension://*

I make use of the existing @connect meta field in TamperMonkey (API).
Currently, the @connect only affect the GM_xmlHttpRequest.
In future, GM_messageExtension will require the userscript to specify the extension id it want to connect in it, too.

use case

Some extensions like TreeStyleTab (api), WebScrapbook or SingleFile
do accept message from other extensions.
E.g, we can trigger WebScrapbook or SingleFile to save a page by sending they a message. (its API)

For myself, I need this API because I want to trigger SingleFile download the webpage easily on android.
Eg, I can put a display:fixed button on some domain with userscript, and click it to trigger the downloading.
Without this, I have to open the browser menu / (scroll and) open extension list / click SingleFile .

who can send message

To accept external message, an extension have to listening on the browser.runtime.onMessageExternal event.
By default, message from all the other extensions and the website specified in the
externally_connectable.matches[] (API) will fire this event,
though Firefox does not support sending message from website now.

Seldom extensions accept message from website, but some accept message from other extensions.
Basically, which website will try to call WebScrapbook or TreeStyleTab?
Extensions can explicitly restrict the source of message by set the externally_connectable.ids[] , too.

about this issue

I have draft a PR for ViolentMonkey.
I just wondering whether other UserScript add-on will interested in this API.
Any comment is welcome!

@douglasg14b
Copy link

Yes please. Really need this sort of capability.

@erosman
Copy link
Owner

erosman commented Jan 19, 2025

Has any other manager implemented the feature?

@GHolk
Copy link
Author

GHolk commented Jan 20, 2025

No, except my fork of violent monkey, purple monkey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants