Treestyletab: TST doesn't detect unload by "suspend tabs" addons (which support TST API)

Created on 23 May 2018  路  9Comments  路  Source: piroor/treestyletab

Short description

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.

Steps to reproduce

  1. Start Firefox with clean profile.
  2. a) Install TST.
    b) Open TST options, use Code snippet,
    for example, this:
.tab.discarded 
{
  opacity: 0.2;
}
  1. a) Install Auto Tab Discard 0.2.8
    b) Open ATD settings. set automatic discarding time to 10 seconds. Just for speed up the experiment.
  2. a) Open google.com,
    b) type some search query, like "test"
    c) open ~10 links from search results
    d) don't visit them, wait for automatic discarding.

Example screenshot:
Piccy.info - Free Image Hosting

Some references:

https://github.com/rNeomy/auto-tab-discard/issues/26
https://github.com/Lej77/tab-unloader-for-tree-style-tab/issues/3

Environment

  • Platform (OS): Windows 10 (x64)
  • Version of Firefox: 60.0.1 (x64)
  • Version (or revision) of Tree Style Tab: 2.4.21
  • Version of Auto Tab Discard: 0.2.8
bug of Firefox itself conflict with another addon

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.

All 9 comments

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:

  • Firefox 60.0.1
  • TST latest development build
  • Ubuntu 16.04LTS

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.)

Environment

  • Platform (OS): Windows 10
  • Version of Firefox: 60, 61 and 62

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.

@piroor I think we could probably close this one.

Was this page helpful?
0 / 5 - 0 ratings