Better error checking

This commit is contained in:
Juhani Krekelä 2021-02-23 05:08:32 +02:00
parent 23e19b48d9
commit 7a4ae9da25
1 changed files with 9 additions and 0 deletions

View File

@ -3,6 +3,10 @@ let bookmarkingTabs = false;
function createFolder(callback) {
chrome.bookmarks.create({'title': 'Autobookmarked Tabs'}, function(folder) {
if (chrome.runtime.lastError) {
setActionStatus('Error bookmarking tabs', 'error', function() {});
return;
}
chrome.storage.local.set({'bookmarksFolder': folder.id});
callback(folder.id);
});
@ -49,12 +53,17 @@ function bookmarkTabs() {
setActionStatus('Bookmarking tabs…', 'processing', function() {
getOrCreateFolder(function(rootId) {
chrome.bookmarks.create({'title': dateString + ' ' + timeString, parentId: rootId}, function(folder) {
if (chrome.runtime.lastError) {
setActionStatus('Error bookmarking tabs', 'error', function() {});
return;
}
chrome.tabs.query({}, function(tabs) {
let remaining = tabs.length;
for (let tab of tabs) {
chrome.bookmarks.create({'title': tab.title, url: tab.url, parentId: folder.id}, function() {
if (chrome.runtime.lastError) {
setActionStatus('Error bookmarking tabs', 'error', function() {});
return;
}
remaining--;