
Is there an API that allows extensions to change vertical tab related settings?
Hi, I want to make a simple extension for Firefox that auto toggles vertical tab based on the aspect ratio of the Firefox window. I found `sidebar.verticalTabs` in about:config that toggles vertical tabs, but a simple googling tells me that it is not possible for web extension to modify about:config values. Is there any other API that toggle vertical tabs? Thanks!
Gekose oplossing
Turns out there is a browserSettings API for vertical tabs after all, but it is on Firefox 142.0 and later.
Kudos to u/Random3838 on r/firefox. Related bugzillas: https://bugzilla.mozilla.org/show_bug.cgi?id=1946600 https://bugzilla.mozilla.org/show_bug.cgi?id=1762975
Lees dié antwoord in konteks 👍 0All Replies (3)
Well, seems like there is no web extension API that can change vertical tab behavior. Instead I created a hack: autoconfig.js
autoconfig.js ```javascript // This file should be in <Firefox binary dir>/defaults/pref pref("general.config.filename", "auto-toggle-vertical-tabs.js"); pref("general.config.obscure_value", 0); pref("general.config.sandbox_enabled", false); ```
auto-toggle-vertical-tabs.js ```javascript // DO NOT DELETE THIS LINE // This file should go to <Firefox binary dir> // support.mozilla.org/en-US/kb/customizing-firefox-using-autoconfig
"use strict";
function shouldUseVerticalTabs(width, height) {
return width <= 1080;
}
try {
let { classes: Cc, interfaces: Ci, manager: Cm, utils: Cu } = Components; var Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;
function ConfigJS() { Services.obs.addObserver(this, "chrome-document-global-created", false); } ConfigJS.prototype = { observe: function (aSubject) { aSubject.addEventListener("DOMContentLoaded", this, { once: true }); }, handleEvent: function (aEvent) { let document = aEvent.originalTarget; let window = document.defaultView; let location = window.location;
window.addEventListener("resize", () => { if (shouldUseVerticalTabs(window.innerWidth, window.innerHeight)) { pref("sidebar.verticalTabs", true); } else { pref("sidebar.verticalTabs", false); } }); }, }; if (!Services.appinfo.inSafeMode) { new ConfigJS(); }
} catch (e) {
Cu.reportError(e);
} ```
The only problem with this script is that vertical tab is a global setting. If you have two windows, one width <= 1080, another width > 1080, then there will be an infinite loop and you will have to forcefully kill one of the window.
There is already a feature request of making vertical tab a per-window setting. You can upvote it here: https://connect.mozilla.org/t5/ideas/vertical-tabs-per-window/idi-p/94064
Gewysig op
Hi
I recommend that you ask about this in the dedicated Add-ons development forum at:
Gekose oplossing
Turns out there is a browserSettings API for vertical tabs after all, but it is on Firefox 142.0 and later.
Kudos to u/Random3838 on r/firefox. Related bugzillas: https://bugzilla.mozilla.org/show_bug.cgi?id=1946600 https://bugzilla.mozilla.org/show_bug.cgi?id=1762975