How does GM_getTab(cb) work?
I'd never attempted to use them, but looking at the code these appear to be the ability to store/get whatever you would like from each tab and also get everything stored in this fashion by all tabs.
On two chrome consoles, I have run the following:
var this_tab_data, all_tabs, n;
GM_getTab(function (o) {
this_tab_data = o;
n = this_tab_data.rand = Math.random();
GM_saveTab(this_tab_data);
console.info(this_tab_data);
GM_getTabs(function (db) {
all_tabs = db;
console.info(n);
for (var i in all_tabs) {
if (all_tabs[i].rand === n) console.info("I bet I am the tab named: " + i);
else console.info("Other tab: " + i + " has value: " + all_tabs[i].rand);
}
});
});
Result (in tab 2):
Object {rand: 0.9303610376082361} VM779:11 0.9303610376082361 VM779:14 Other tab: 366 has value: 0.417106909211725 VM779:13 I bet I am the tab named: 371
I added access in the chrome console using this user script, (based on the instructions on the indicated @match
page):
// ==UserScript==
// @name My Fancy New Userscript
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match http://stackoverflow.com/questions/14059078/use-the-tampermonkey-api-from-the-chrome-console
// @copyright 2012+, You
// ==/UserScript==
unsafeWindow.GM_getTab = GM_getTab;
unsafeWindow.GM_saveTab = GM_saveTab;
unsafeWindow.GM_getTabs = GM_getTabs;
As a side note, I see that this data remains accessible with GM_getTabs() after I close the tabs that set it. I'm not sure I would count on that, but I probably would minimize what I left behind.