One of the challenges I'm facing is with my Firefox extension, where a function loads page information using the following code:
var title = content.document.title;
var url = content.document.location.href;
However, with the implementation of multi-process Firefox (Electrolysis/e10s) that doesn't support direct content access, this method no longer works. I am attempting to refactor this code into a frame script, but I'm encountering difficulties in understanding how to "call" this code due to its asynchronous nature. Below is what I believe should be a simple frame script:
// Frame script
function getPageInfo()
{
sendSyncMessage("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="68051145090c0c45070628050d460b0705">[email protected]</a>:page-info-loaded", {
pageURL : content.document.location.href,
pageTitle : content.document.title
});
}
addMessageListener("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb8692c68a8f8fc68485ab868ec5888486">[email protected]</a>:get-page-info", getPageInfo);
I believe the relevant chrome code should resemble the following:
// Chrome script
function onContextItem()
{
let browserMM = gBrowser.selectedBrowser.messageManager;
browserMM.loadFrameScript("chrome://my-add-on/content/frame-script.js", true);
browserMM.sendAsyncMessage("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dcb1a5f1bdb8b8f1b3b29cb1b9f2bfb3b1">[email protected]</a>:get-page-info");
}
function onInfoLoaded(message)
{
var url = message.data.pageURL;
var title = message.data.pageTitle;
// Perform actions based on url and title
}
gBrowser.selectedBrowser.messageManager
.addMessageListener("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8fe2f6a2eeebeba2e0e1cfe2eaa1ece0e2">[email protected]</a>:page-info-loaded", onInfoLoaded);
The challenge lies in my incomplete understanding of whether (a) this approach is correct or (b) how the timing aspect plays out. Due to the asynchronous messaging system, there's uncertainty if the data I require will return in time for use. None of the examples provided by Mozilla seem to align with my specific needs. Could I be overlooking something evident? Are there superior examples demonstrating how to adapt extension code to accommodate e10s?