TST doesn't always detect unload by "suspend tabs" addons (which support TST API)
Thus, tab is actually unloaded however, the marking of unloaded tabs with gray shading doesn't always works. It happens randomly.
.tab.discarded
{
opacity: 0.2;
}
https://github.com/rNeomy/auto-tab-discard/issues/26
https://github.com/Lej77/tab-unloader-for-tree-style-tab/issues/3
I tried the steps described, but I couldn't reproduce the problem. Tabs opened from search results are unloaded after some delay and style rules for .tab.discarded. CSS codes I actually used are:
.tab.discarded { background: green !important; }
.tab.discarded * { color: white !important; }
Environment:
This problem doesn't always occur.
I can't reproduce the "issue algorithm" to get it always.
Temporary workaround - the dimming works correctly if you call the discard method once again,
manually, on the unloaded BUT not dimmed tab.
Maybe @Lej77 thoughts can help:
The issue is probably still that Firefox tells extensions that the tab is loaded even though it isn't. This seems to happen if a content script is sending a message when it is being unloaded and my pull request prevents one such message.
If this is the reason for this issue then it would be quite hard to fix with in Tree Style Tab's code. If the problem is because of Firefox's tracking then I see two solutions. Either stop the message that is being sent when the tab is unloaded or call the discard function twice (once to unload the tab and another to fix the incorrect Firefox state).
@perdolka I'm pretty sure this is bug of Firefox itself. It makes it so that tabs have discarded set to false even though they aren't loaded. I just released a new version (v5.5) of Tab Unloader for Tree Style Tab that includes a workaround that should fix such an issue for all unloaded tabs (even those not unloaded by my extension). It does this by listening to the browser.tabs.onUpdate event and if a tab has discarded set to true and then immediately after have discarded set to false and no tab.status or tab.url changes are observed after it is "loaded" then its probably this bug so it then unloads the tab again which sets discarded to true.
@Lej77 Hmm, is the bug tracked on bugzilla.mozilla.org?
@piroor I haven't found it there but I haven't looked that much either. Anyway I wrote a small test extension to reproduce the false loaded state.
manifest.json:
{
"manifest_version": 2,
"name": "Mark tab as loaded when unloaded",
"version": "1.0",
"applications": {
"gecko": {
"strict_min_version": "58.0"
}
},
"permissions": [
"menus",
"<all_urls>"
],
"background": {
"scripts": [
"background.js"
]
}
}
background.js:
browser.menus.create({
id: "fake-unload-tab",
title: "Unload and mark as loaded",
contexts: ["tab"]
});
browser.menus.onClicked.addListener(async function (info, tab) {
switch (info.menuItemId) {
case 'fake-unload-tab': {
browser.tabs.discard(tab.id);
browser.tabs.executeScript(tab.id, { code: `browser.runtime.sendMessage({});`, runAt: 'document_start', });
} break;
}
});
browser.runtime.onMessage.addListener((message, sender) => {
});
Only tabs with pages that can have content scripts can be put in the fake loaded state since a message needs to be sent from the page when it is being unloaded. Also the problem can't be reproduced 100% of the time but it appears most of the time. Sometimes it doesn't work for a particular tab or page so test different ones if it doesn't work. (Note: the context menu item won't work for the active tab since it will be ignored by the browser.tabs.discard function.)
Thanks, I've modified your sample code a little:
testcase.xpi.zip
I've confirmed that actually tabs are shown as "not discarded" when reload or executeScript is executed for discarded tab immediately.
1464992 - Immediate operations after tabs.discard() disposes tab's "discarded" attribute but the tab is actually still discarded
https://bugzilla.mozilla.org/show_bug.cgi?id=1464992
I've reported this problem to bugzilla.mozilla.org.
1422588 - a tab discarded immediately after creation gains a corrupted session state.
This problem should be fixed on Firefox 62.
@piroor I think we could probably close this one.
Most helpful comment
1464992 - Immediate operations after tabs.discard() disposes tab's "discarded" attribute but the tab is actually still discarded
https://bugzilla.mozilla.org/show_bug.cgi?id=1464992
I've reported this problem to bugzilla.mozilla.org.