How to add onload listener without XUL in Thunderbird Addon?

275 Views Asked by At

My goal is to access the current Text in the editor when composing a message with Thunderbird.

Before Thunderbird 68 my extension could access the text by

chrome.manifest:

overlay chrome://editor/content/editorOverlay.xul chrome://ext/content/extEditor.xul

extEditor.xul:

<overlay id="x" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     <script type="application/javascript" charset="UTF-8" src="chrome://ext/content/extEditor.js"/>
</overlay>

extEditor.js:

document.getElementById("content-frame").addEventListener("keypress", 
                                    function(e) { 
                                        // do stuff; 
                                    },
                                    false);

As of now mozilla wants to get rid of XUL. I'm rewriting the extension to fit it into the new MailExtension system.

Does anyone know how to add an onload listener to the msgcomposeWindow like this without XUL? I guess I need a statement like this

document.getElementById("msgcomposeWindow").addEventListener("onload", function (e) {
    ///
});

in the main messenger window but it gives me null return because obviously on starting thunderbird there is no msgcomposeWindow yet.

1

There are 1 best solutions below

0
opto On

xul: make an observer for windows. Test their windowtype. If it is the right one for the composewindow, add your listener. You can see the windowtype in debugger/inspector for the compose window.

For new webextensions, new access to compose has been added since: https://thunderbird-webextensions.readthedocs.io/en/latest/compose.html#onbeforesend-tab-details

see also the composeaction