Closed Bug 1630786 Opened 5 months ago Closed 5 months ago

Content scripts in message composition editor

Categories

(Thunderbird :: Add-Ons: Extensions API, enhancement)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 77.0

People

(Reporter: darktrojan, Assigned: darktrojan)

References

Details

Attachments

(2 files, 1 obsolete file)

No description provided.

This is the first part, making insertCSS, removeCSS and executeScript work. Philipp I'm r?ing you for this because you understand the internals I'm tapping in to better, and I want to know if I'm doing anything stupid before going further.

Attachment #9141118 - Flags: review?(philipp)
Attachment #9141118 - Flags: review?(philipp) → feedback?(philipp)
Attachment #9141118 - Attachment is obsolete: true
Attachment #9141118 - Flags: feedback?(philipp)
Attachment #9143546 - Flags: review?(mkmelin+mozilla)
Attachment #9143546 - Flags: feedback?(philipp)
Attachment #9143547 - Flags: review?(mkmelin+mozilla)

Part two adds a new composeScripts API which is similar to the contentScripts API except that it works with the compose window and requires the compose permission. Also it doesn't have most of the options of that API because they're irrelevant.

There is a part three to this bug, which is to register scripts straight from the extension manifest, but I am not hopeful that it will ever happen because an extension context is needed, and it isn't available when reading the manifest.

Comment on attachment 9143546 [details] [diff] [review]
1630786-pt1-insertcss-removecss-executescript-2.diff

Review of attachment 9143546 [details] [diff] [review]:
-----------------------------------------------------------------

Can't claim any deeper understanding, but looks ok to me. r=mkmelin

::: mail/components/extensions/parent/ext-mail.js
@@ +759,5 @@
>      return false;
>    }
>  
> +  /** Returns true if this tab is a compose window "tab". */
> +  get composeTab() {

I see there is mailTab already. But would it be better naming with isComposeTab and isMailTab?
Attachment #9143546 - Flags: review?(mkmelin+mozilla) → review+
Comment on attachment 9143547 [details] [diff] [review]
1630786-pt2-register-1.diff

Review of attachment 9143547 [details] [diff] [review]:
-----------------------------------------------------------------

::: mail/components/compose/content/MsgComposeCommands.js
@@ +8380,5 @@
>    if (AppConstants.platform != "macosx") {
>      AutoHideMenubar.init();
>    }
> +
> +  dispatchEvent(new CustomEvent("compose-editor-ready"));

maybe clearer to make this
window.dispatchEvent(

::: mail/components/extensions/schemas/composeScripts.json
@@ +22,5 @@
> +          },
> +          "js": {
> +            "type": "array",
> +            "optional": true,
> +            "description": "The list of JS files to inject",

nit: maybe JavaScript instead of JS

::: mail/components/extensions/test/browser/browser_ext_composeScripts.js
@@ +247,5 @@
>    await extension.awaitFinish("finished");
>    await extension.unload();
>  });
> +
> +add_task(async function testRegisterBeforeCompose() {

plcase add a quick documentation for each task, what it's checking for
Attachment #9143547 - Flags: review?(mkmelin+mozilla) → review+

Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/9e23d0584abc
part 1 - Support insertCSS/removeCSS/executeScript in compose windows. r=mkmelin
https://hg.mozilla.org/comm-central/rev/263dae2cae3f
part 2 - Allow registration of content scripts in the compose window. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 5 months ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 77.0
Attachment #9143546 - Flags: feedback?(philipp)

I tested this API and found a few issues. I am not sure if I should file separate bugs or if these can be fixed in a followup:

  • The messenger.* namespace/variable is undefined.
  • There is no way to view the Console for the compose scripts, which makes them extremely difficult to debug. If you select the compose window from the "Developer Toolbox", the Console is blank.
  • The compose scripts API only works for the message body, not the subject. I am working on an emoji picker/autocorrect extension and need to be able to insert emojis into the subject.
  • There is no way to send messages to the compose scripts, for example when the user updates the options, as Thunderbird does not have an equivalent API to Firefox's browser.tabs.sendMessage().
  • Not directly related to this bug, but option pages are also busted in Thunderbird 77, which makes extensions difficult to test in general. No issues in Thunderbird 68 or in Firefox. I get these errors in the Console:
NS_ERROR_FILE_NOT_FOUND: Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIStyleSheetService.preloadSheet] ExtensionCommon.jsm:2587
TypeError: prin.URI is null
ConduitsParent.jsm:123:58
Error: Unknown sender or wrong actor for recvCreateProxyContext ConduitsParent.jsm:321:13
TypeError: prin.URI is null
ConduitsParent.jsm:123:58
Error: Unknown sender or wrong actor for recvAPICall ConduitsParent.jsm:321:13
Error: Unknown sender or wrong actor for recvAPICall 2 ConduitsParent.jsm:321:13
Error: Unknown sender or wrong actor for recvAddListener 2 ConduitsParent.jsm:321:13
Error: Unknown sender or wrong actor for recvAPICall 22 ConduitsParent.jsm:321:13

Yes, you should file separate bugs. This one is closed.

The compose scripts API only works for the message body, not the subject. I am working on an emoji picker/autocorrect extension and need to be able to insert emojis into the subject.

Not for this, there are other methods for changing the subject

There is no way to view the Console for the compose scripts, which makes them extremely difficult to debug. If you select the compose window from the "Developer Toolbox", the Console is blank.

AFAIK, there's no way to do this with content scripts in Firefox either. This is because they don't have a document of their own, they're working on a content document. You can find this document using the full Developer Toolbox, but still debugging is not easy.

OK.

AFAIK, there's no way to do this with content scripts in Firefox either. This is because they don't have a document of their own, they're working on a content document. You can find this document using the full Developer Toolbox, but still debugging is not easy.

In Firefox, if you do console.log() from a content script, the output is shown in the Console for the tab. Yes, in Thunderbird you can find the compose window document from the "Developer Toolbox", but the Console is blank.

Duplicate of this bug: 1594875
You need to log in before you can comment on or make changes to this bug.