Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const widgets = require("widget");
const tabs = require("tabs");
var tabArray = [];
var widget = widgets.Widget({
label: "Show tab history",
id: 'tab history',
contentURL: "http://www.mozilla.org/favicon.ico",
onClick: function() {
console.log('\n tab history:');
let n = 0;
tabArray.forEach(function(tab) {
console.log('tab ' + n + ':');
n++;
tab.history.forEach(function(url) {
console.log(url);
});
});
}
});
tabs.on('open', function(tab) {
tab.history = [];
tabArray.push(tab);
});
tabs.on('ready', function(tab) {
// we need this special-case code
// because 'open' does not get generated
// for the first tab in the window
if (!tab.history) {
tab.history = [];
tabArray.push(tab);
}
tab.history.push(tab.url);
});
tabs.on('close', function(tab) {
var index = tabArray.indexOf(tab);
if (index != -1) {
tabArray.splice(index, 1);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment