I made a workaround that currently functions well on Thunderbird 68b01
However in Thunderbird Daily 69 the window onload event will fire before my overlayed JavaScript files get a chance to execute.
from the manifest:
overlay chrome://messenger/content/messengercompose/messengercompose.xul chrome://smarttemplate4/content/messengercomposeOverlay.xul
from the overlay xul file
<script type="application/javascript" src="chrome://smarttemplate4/content/smartTemplate-main.js"/>
<script type="application/javascript" src="chrome://smarttemplate4/content/smartTemplate-compose.js"/>
<script type="application/javascript" src="chrome://smarttemplate4/content/smartTemplate-overlay.js"/>
<script type="application/javascript" src="chrome://smarttemplate4/content/smartTemplate-util.js"/>
<script type="application/javascript" src="chrome://smarttemplate4/content/smartTemplate-composer.js"/>
...
smartTemplate-composer.js contains the following function:
window.setTimeout (function()
{
const util = SmartTemplate4.Util,
logDebugOptional = util.logDebugOptional.bind(util),
isDebugComposer = SmartTemplate4.Preferences.isDebugOption('composer');
let txt = "unknown";
try { txt = window.document.firstElementChild.getAttribute('windowtype'); }
catch(ex) {;}
logDebugOptional('composer', "Adding compose-window-init event listener for msgcomposeWindow...");
let composer = document.getElementById("msgcomposeWindow");
composer.addEventListener("compose-window-init", SmartTemplate4.initListener, false);
SmartTemplate4.init();
// debugger;
util.logDebug("Calling SmartTemplate4.composer.load from window: " + txt);
// safety for when the compose-window-init event does not fire (Tb 67+)
if (typeof ComposeStartup == 'function') {
// if (util.versionGreaterOrEqual(util.AppverFull, "61"))
if (!SmartTemplate4.ComposeStartup) {
if (isDebugComposer) debugger;
SmartTemplate4.ComposeStartup = ComposeStartup;
ComposeStartup = function() {
logDebugOptional('composer','Calling ComposeStartup Wrapper');
SmartTemplate4.ComposeStartup();
logDebugOptional('composer','Calling initListener');
SmartTemplate4.initListener(true);
}
}
}
SmartTemplate4.composer.load();
},10
);
... by the time the line
composer.addEventListener("compose-window-init", SmartTemplate4.initListener, false);
is executed ComposeStartup() has already been executed and the "compose-window-init" event dispatched. I wonder if there is any way to make sure the onload is not executed until all overlays are loaded. If not, I will have to think of other ways (lower level window management) to check whether the composer window has been loaded.
Bug 1559533 Comment 2 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
I made a workaround that currently functions well on Thunderbird 68b01
However in Thunderbird Daily 69 the window onload event will fire before my overlayed JavaScript files get a chance to execute.
from the manifest:
overlay chrome://messenger/content/messengercompose/messengercompose.xul chrome://smarttemplate4/content/messengercomposeOverlay.xul
from the overlay xul file:
<script type="application/javascript" src="chrome://smarttemplate4/content/smartTemplate-main.js"/>
<script type="application/javascript" src="chrome://smarttemplate4/content/smartTemplate-compose.js"/>
<script type="application/javascript" src="chrome://smarttemplate4/content/smartTemplate-overlay.js"/>
<script type="application/javascript" src="chrome://smarttemplate4/content/smartTemplate-util.js"/>
<script type="application/javascript" src="chrome://smarttemplate4/content/smartTemplate-composer.js"/>
...
smartTemplate-composer.js contains the following function:
window.setTimeout (function()
{
const util = SmartTemplate4.Util,
logDebugOptional = util.logDebugOptional.bind(util),
isDebugComposer = SmartTemplate4.Preferences.isDebugOption('composer');
let txt = "unknown";
try { txt = window.document.firstElementChild.getAttribute('windowtype'); }
catch(ex) {;}
logDebugOptional('composer', "Adding compose-window-init event listener for msgcomposeWindow...");
let composer = document.getElementById("msgcomposeWindow");
composer.addEventListener("compose-window-init", SmartTemplate4.initListener, false);
SmartTemplate4.init();
// debugger;
util.logDebug("Calling SmartTemplate4.composer.load from window: " + txt);
// safety for when the compose-window-init event does not fire (Tb 67+)
if (typeof ComposeStartup == 'function') {
// if (util.versionGreaterOrEqual(util.AppverFull, "61"))
if (!SmartTemplate4.ComposeStartup) {
if (isDebugComposer) debugger;
SmartTemplate4.ComposeStartup = ComposeStartup;
ComposeStartup = function() {
logDebugOptional('composer','Calling ComposeStartup Wrapper');
SmartTemplate4.ComposeStartup();
logDebugOptional('composer','Calling initListener');
SmartTemplate4.initListener(true);
}
}
}
SmartTemplate4.composer.load();
},10
);
... by the time the line:
`composer.addEventListener("compose-window-init", SmartTemplate4.initListener, false);`
is executed, **ComposeStartup()** has already been executed and the "compose-window-init" event dispatched. I wonder if there is any way to make sure the onload is not executed until all overlays are loaded. If not, I will have to think of other ways (lower level window management) to check whether the composer window has been loaded.