Works only in Gecko 20.0 and higher because used API doesn't exist in older versions!
We just inherit private state from selected tab and tries preserve private state of dropped link-like things, this is simple to implement, but may confuse a bit…
You can use .tabbrowser-tab[privateTab-isPrivate]
(private tab) and #main-window[privateTab-isPrivate]
(built-in private window) selectors in styles for userChrome.css/Stylish.
Example styles:
- change underline of private tabs
- change icon
- change background color
- add overlay icon
- add icons to menu items
You can listen for following events:
event.type | event.target | event.detail | Description |
---|---|---|---|
PrivateTab:PrivateChanged | tab | 1 – private tab 0 – not private | Changed private state of the tab |
PrivateTab:OpenInNewTab | tab | 1 – may be opened as child tab | Link was opened in new private tab |
PrivateTab:OpenNewTab | tab | – | Opened new (empty) private tab |
boolean privateTab.isTabPrivate(in DOMNode tab)
boolean privateTab.toggleTabPrivate(in DOMNode tab[, in boolean isPrivate])
void privateTab.readyToOpenTab(in boolean isPrivate)
void privateTab.readyToOpenTabs(in boolean isPrivate)
Investigates that the tab are private (true
) or not (false
), example:
// Close all (visible) private tabs:
Array.slice(gBrowser.visibleTabs || gBrowser.tabs).forEach(function(tab) {
if(privateTab.isTabPrivate(tab))
gBrowser.removeTab(tab);
});
Changes tab private state:
Toggle: privateTab.toggleTabPrivate(tab)
Make private: privateTab.toggleTabPrivate(tab, true)
Make not private: privateTab.toggleTabPrivate(tab, false)
// Make all (visible) tabs private:
Array.forEach(
gBrowser.visibleTabs || gBrowser.tabs,
function(tab) {
if(!privateTab.isTabPrivate(tab))
privateTab.toggleTabPrivate(tab, true);
}
);
Allows to open private or not private tab (independent of any inheritance mechanism), example:
// Open in private tab:
privateTab.readyToOpenTab(true);
gBrowser.addTab("https://mozilla.org/");
// Open in not private tab:
privateTab.readyToOpenTab(false);
gBrowser.addTab("https://mozilla.org/");
Allows to open many private or not private tabs (independent of any inheritance mechanism), example:
// Open in private tabs:
privateTab.readyToOpenTabs(true);
gBrowser.addTab("https://mozilla.org/");
gBrowser.addTab("https://addons.mozilla.org/");
// ...
privateTab.stopToOpenTabs();
Check for Private Tab installed (and enabled):
if("privateTab" in window) {
// Do something with "privateTab" object
}