Let WebExtensions preload their new tab page
Categories
(Firefox :: New Tab Page, enhancement, P2)
Tracking
()
People
(Reporter: clessili, Unassigned)
References
(Blocks 1 open bug)
Details
It would be nice if Firefox could preload an extension's new tab page instead of the default one.
Currently Firefox's New tab page is preloaded even if an extension replaces it, so it uses some memory but it doesn't speed up the new tab.
Updated•4 years ago
|
I had a bit of time at hand and decided to pull the code and look around. I think it could be done.
I tried removing the two last checks in browser/modules/NewTabPagePreloading.jsm
line 39:
before:
this.prefEnabled && this.newTabEnabled && !AboutNewTab.newTabURLOverridden
after:
this.prefEnabled
(of course there should be something to check if the extension's developer wants his homepage to be preloaded)
...but later ran into an error because of these lines related to SessionStore, in browser/base/content/tabbrowser.js
, line 2076:
// Ensure that SessionStore has flushed any session history state from the
// content process before we this browser's remoteness.
if (!Services.appinfo.sessionHistoryInParent) {
b.prepareToChangeRemoteness = () =>
SessionStore.prepareToChangeRemoteness(b);
b.afterChangeRemoteness = switchId => {
let tab = this.getTabForBrowser(b);
SessionStore.finishTabRemotenessChange(tab, switchId);
return true;
};
}
However, as that bit of code implies, enabling the config fission.sessionHistoryInParent
completely skips these few functions and the WebExtension's homepage is correctly preloaded and instantly rendered!
If fission.sessionHistoryInParent
is destined to become true by default, this bug could be resolved.
The only remaining issue I see would be deciding a way for extension developers to explicitly preload their homepage. I guess it would mean deciding a new manifest config with the other browser vendors?
Updated•2 years ago
|
Comment 2•2 years ago
|
||
Needing to come up with a new manifest key is probably gonna slow this down a lot. Idk, seems like Firefox could just assume all new tab pages want to be preloaded and merely add an opt-out pref for users. But I haven't tried too many new tab page addons, idk if it will break many of them.
just assume all new tab pages want to be preloaded
This might lead to some surprises for addon developers and users if they don't know about the feature. Since the preloading script keeps 3 home pages open in background at all time, any change to localStorage applied in one New Tab will not immediately appear on the next New Tab.
In my case, I had to add some code to refresh the preloaded page if localStorage has changed & page visibility is "hidden", like this:
// page is loaded in background, it's being preloaded, listen for storage changes
if (document.visibilityState === "hidden") {
chrome.storage.onChanged.addListener(doReload);
}
// page shifts to foreground
document.addEventListener("visibilitychange", function() {
if (document.visibilityState === "visible") {
chrome.storage.onChanged.removeListener(doReload);
}
});
function doReload() {
location.reload();
}
For some reason in the latest Nightly I'm not seeing any issue with or without fission.sessionHistoryInParent
enabled. Could we try changing that check in NewTabPagePreloading.jsm?
Updated•2 years ago
|
Description
•