support icon indicating copy to clipboard operation
support copied to clipboard

Add GM_messageExtension allowing userscript to trigger other WebExtension in FireMonkey

Open GHolk opened this issue 1 year ago • 3 comments

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!

GHolk avatar Jul 21 '24 04:07 GHolk

Yes please. Really need this sort of capability.

douglasg14b avatar Jan 18 '25 22:01 douglasg14b

Has any other manager implemented the feature?

erosman avatar Jan 19 '25 05:01 erosman

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

GHolk avatar Jan 20 '25 12:01 GHolk