-
-
Save jscher2000/b7094b3e74b95e5ba9c26f1f685bda6e to your computer and use it in GitHub Desktop.
| // Run code in Browser Console after enabling chrome debugging -- | |
| // about:config => devtools.chrome.enabled => true | |
| // https://developer.mozilla.org/docs/Tools/Browser_Console | |
| try { | |
| var tabPromise = SyncedTabs._internal.getTabClients(); | |
| tabPromise.then((arrDevices) => { | |
| if (arrDevices && arrDevices.length > 0){ | |
| // Generate a string with the format of a bookmark export file | |
| var d, e, out = '<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">\n<TITLE>Bookmarks</TITLE>\n<H1>Bookmarks Menu</H1>\n<DL><p>\n'; | |
| const escapeHtmlEntities = function(aText){return (aText || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''')}; | |
| for (var j=0; j<arrDevices.length; j++){ | |
| // Create a folder for each device | |
| d = new Date(arrDevices[j].lastModified); | |
| e = Math.floor(d.getTime()/1000); | |
| out += '<DT><H3 ADD_DATE="' + e + '" LAST_MODIFIED="' + e + '">Synced Tabs from ' + escapeHtmlEntities(arrDevices[j].name) + ' as of ' + d.toString() + '</H3>\n<DL><p>\n'; | |
| // Sort tabs by most recently used | |
| var arrTabs = arrDevices[j].tabs; | |
| arrTabs.sort(function(a, b){return b.lastUsed - a.lastUsed;}); | |
| for (var i=0; i<arrTabs.length; i++){ | |
| // Create a bookmark (link) for each tab | |
| d = new Date(arrTabs[i].lastUsed * 1000); | |
| e = Math.floor(d.getTime()/1000); | |
| out += ' <DT><A HREF="' + arrTabs[i].url + '" ADD_DATE="' + e + '" LAST_MODIFIED="' + e + '">' + escapeHtmlEntities(arrTabs[i].title) + '</A>\n'; | |
| // Show last access date/time in a note (comment out or delete the next line if you don't want that) | |
| out += ' <DD>Last acccessed: ' + d.toString() + '\n' | |
| } | |
| out += '</DL><p>\n'; | |
| } | |
| out += '</DL><p>\n</DL>'; | |
| // Set up Save As dialog with proposed file name | |
| var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker); | |
| try { // Fx125+ | |
| fp.init(window.browsingContext, 'Open File', Components.interfaces.nsIFilePicker.modeSave); | |
| } catch(e) { // Fx124 and earlier | |
| fp.init(window, 'Open File', Components.interfaces.nsIFilePicker.modeSave); | |
| } | |
| fp.appendFilter('HTML Files', '*.html'); | |
| d = new Date(); | |
| d.setMinutes(d.getMinutes() - d.getTimezoneOffset()); | |
| var dt = d.toISOString().split('.')[0].replace(/-/g, '').replace(/:/g, '').replace(/T/, '_'); | |
| fp.defaultString = 'bookmarks-from-synced-tabs_' + dt + '.html'; | |
| // Call Save As dialog and (unless user cancels) write the file | |
| fp.open((aResult) => { | |
| if (aResult == Components.interfaces.nsIFilePicker.returnOK || | |
| aResult == Components.interfaces.nsIFilePicker.returnReplace) { | |
| try { | |
| IOUtils.writeUTF8(fp.file.path, out); | |
| alert('Look for ' + fp.file.path); | |
| } catch (err) { | |
| alert(err); | |
| } | |
| } else { | |
| alert('Okay, not saving'); | |
| } | |
| }); | |
| } else { | |
| console.log('NO SYNCED TABS RETRIEVED'); | |
| } | |
| }).catch((err) => { | |
| console.log('Problem reading or outputting synced tabs: '+err); | |
| }); | |
| } catch (err) { | |
| console.log('Problem reading or outputting synced tabs: '+err); | |
| } |
Not working, likely related to recent changes in sync.
Error: "Problem reading or outputting synced tabs: ReferenceError: SyncedTabs is not defined"
Not working, likely related to recent changes in sync. Error: "Problem reading or outputting synced tabs: ReferenceError: SyncedTabs is not defined"
Could you double-check to make sure you are running the script in the Browser Console (runs at the parent level), not the Web Console (runs at the tab level only for the content): https://firefox-source-docs.mozilla.org/devtools-user/browser_console/index.html
hi, thank you so much for this! The latest FF Android version seems to have broken all my existing ways of exporting all open tabs and this did work to generate the bookmark file of synced tabs. I tweaked the code so it just outputs a list of linked URLs rather than using the titles, but I don't know enough about JS to figure something else out... Is it possible to have the list retain the sorting of the original tabs, rather than sort based on time accessed?
Is it possible to have the list retain the sorting of the original tabs, rather than sort based on time accessed?
You could try removing this line to see the "natural" order (I can't remember what it is):
arrTabs.sort(function(a, b){return b.lastUsed - a.lastUsed;});
Really useful script; thanks.