rNeomy / auto-tab-discard

Use native tab discarding method to automatically reduce memory usage of inactive tabs
https://webextension.org/listing/tab-discard.html
Mozilla Public License 2.0
888 stars 76 forks source link

API for unloading tabs from other addons doesn't work for new tab pages #318

Closed Lej77 closed 1 year ago

Lej77 commented 1 year ago

Description

My Tab Unloader for Tree Style Tab extension allows unloading tabs by sending a discard message to Auto Tab Discard. This has worked really well but I noticed that recently this stopped working for special Firefox tabs such as new tab pages (about:newtab).

I debugged my extension and found that the Auto Tab Discard message was never responded to and therefore the message promise never resolved. I then debugged Auto Tab Discard itself and found that at line 13 of auto-tab-discard/core.mjs the message handler throws an error because the url property is undefined.

I think this issue should be fixed if a check is added so that url is "truthy", for example by changing the condition to Boolean(url) && (url.startsWith('http') || url.startsWith('ftp')) && !discarded && !active.

I thought about working around this in my extension but it doesn't have permission to access URLs so I can't check what tab is being unloaded before sending the message to Auto Tab Discard.

Steps to reproduce

  1. Start Firefox with clean profile.
  2. Install Auto Tab Discard.
  3. Install Tab Unloader for Tree Style Tab.
  4. Go to Tab Unloader for Tree Style Tab's settings page and in the Other Settings section enable the Unload tabs via the Auto Tab Discard extension option.
  5. Use Tab Unloader for Tree Style Tab to unload a "New Tab" page, for example by right clicking on such a tab and selecting the Unload Tab(s) context menu item.
    • If Tree Style Tab is installed then it is easier to see what tabs are actually unloaded since they are dimmed in the sidebar. (At least if Tab Unloader for Tree Style Tab's style rules are registered, so might need to disable and re-enable Tab Unloader for Tree Style Tab after installing Tree Style Tab.)

Expected result

The "New Tab" page should be unloaded.

Actual result

The "New Tab" remains loaded.

Environment

rNeomy commented 1 year ago

Thanks for the report. Does 334d95b fix the issue? btw, since ATD filters tabs from external requests (HTTP && HTTPS only), I am not sure how the blank one got discarded.

rNeomy commented 1 year ago

ATD.zip

Lej77 commented 1 year ago

Thanks for the quick follow-up! I tested with ATD.zip and this issue seems to have been fixed!

The unloading of blank tabs is actually handled by my extension. It has some logic to handle tabs that cannot be unloaded by Auto Tab Discard at line 139 of tab-unloader-for-tree-style-tab/background.js. This affects tabs in private windows (if ATD hasn't been granted permission for private windows) and tabs that have weird URLs such as about:newtab. My extension's fallback code waits for ATD to finish with the unload request and since that didn't happen the fallback code never unloaded the blank tabs.