Closed Bug 1233436 Opened 10 years ago Closed 10 years ago

[e10s] frame scripts loaded via a browser messagemanager are unloaded on location change

Categories

(Core :: DOM: Content Processes, defect)

44 Branch
x86_64
Linux
defect
Not set
major

Tracking

()

RESOLVED WONTFIX

People

(Reporter: laurent, Unassigned)

Details

As the documentation says, "Frame scripts are associated with a browser tab, not with a page. So once you load them, they stay loaded until the tab is closed, even if you reload the document or navigate.". (https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Frame_script_loading_and_lifetime#Frame_script_lifetime) It is true with Firefox 43 and 44a2 with e10s disabled. Its not true anymore when e10s is enabled. It seems the frame script goes away when the location of the tab is changed. Consider this addons script: exports.main = function(aOptions, aCallback) { var { viewFor } = require("sdk/view/core"); var tabsUtils = require("sdk/tabs/utils"); var tabs = require("sdk/tabs"); function trackTab(tab) { let xulTab = viewFor(tab); let browser = tabsUtils.getBrowserForTab(xulTab); browser.messageManager.loadFrameScript('resource://myaddon/frame-script.js', true); } tabs.on('open', trackTab); } A frame script is loading into the content process with the message manager of the browser corresponding to each tabs. And here is the frame-scripts: addEventListener('DOMWindowCreated', function(event){ dump("----- DOMWindowCreated "+content.location.href+"\n") }); addEventListener('DOMContentLoaded', function(event){ dump("----- DOMContentLoaded "+content.location.href+"\n") }); addEventListener('unload', function(event){ dump("----- unload "+content.location.href+"\n") }); Then follow these steps : - start Firefox from the command line - open a new tab - load a web site, for instance http://slimerjs.org - close the tab - read the console output in the shell With disabled e10s, the output is: (<something> are my comments) <tab is opened> ----- DOMWindowCreated about:newtab ----- DOMContentLoaded about:newtab <url is entered> ----- DOMWindowCreated http://slimerjs.org/ ----- DOMContentLoaded http://slimerjs.org/ <tab is closed> ----- unload http://slimerjs.org/ With enabled e10s <tab is opened> ----- DOMWindowCreated about:newtab ----- DOMContentLoaded about:newtab <url is entered> ----- unload about:newtab <tab is closed> When we enter the url in the new tab, the frame-script received the "unload" events and nothing else. No more DOMWindowCreated or DOMContentLoaded events. Since the behavior is not the same between e10s and non-e10s context, this bug may break some addons (and it breaks mine :-/)
Note: it works well with the global message manager, and the example here could use it since it loads the frame script in all tabs. But it may not be what we want, and we may have to use the browser message manager instead the global one...
Bill, correct me if I'm wrong, but I think this is how this is supposed to work.
Flags: needinfo?(wmccloskey)
After more tests, here what I found : If the tab is opened with "about:newtab" (with the "+" button on tabs toolbar for example), the frame script is unloaded when we enter a new URL and is not reloaded for the new web site. If the tab is opened directly with the web site, for example with a middle-button-click on bookmarks or a link in an other tab, the frame script is loaded and stays until the tab is closed. So it seems there is an issue with "about:newtab" and content processes.
Yes, this is a danger of using frame scripts. Sometimes we need to switch a tab from remote (runs in a content process) to non-remote (runs in the main Firefox process). That happens when you load about:newtab. Any frame scripts that were loaded for the tab are unloaded and no longer apply. We don't really have any way to fix this. You're better off using the browser or global message manager.
Status: NEW → RESOLVED
Closed: 10 years ago
Flags: needinfo?(wmccloskey)
Resolution: --- → WONTFIX
>Any frame scripts that were loaded for the tab are unloaded and no longer apply. Why don't you reload them to avoid the danger ? This is what is done by the global message manager ! If I use the global message manager, here is the output <tab is opened> ----- DOMWindowCreated about:newtab ----- DOMContentLoaded about:newtab <url is entered> ----- unload about:newtab ----- DOMWindowCreated http://slimerjs.org/ ----- DOMContentLoaded http://slimerjs.org/ <tab is closed> ----- unload http://slimerjs.org/ The frame script is reloaded. So, it shows this is possible. The problem by using the global message manager, is that it is more difficult to follow data and messages produced by the frame-script *per tab*. And probably, by not resolving this issue, you may have problems with toolkit/content/browser-child.js, right?
You need to log in before you can comment on or make changes to this bug.