From ef2a02577e732c66a34f2b867518331b252661f8 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sat, 19 Sep 2020 02:05:33 +0200 Subject: [PATCH] wrap in try and update more often --- src/background/index.js | 47 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/background/index.js b/src/background/index.js index 08f76dc..967cc3c 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -5,32 +5,33 @@ import { insertLog, normalizeTimestamp } from '../shared/db' browser.browserAction.onClicked.addListener(() => browser.tabs.create({ url: dashboard, active: true })) -const frequency = 3000 +const frequency = 1000 async function getAllTabs() { - console.log('Checking...') - const tabs = await browser.tabs.query({}) - const windows = await browser.windows.getAll() - const active = tabs - .filter((tab) => { - const window = windows.find((window) => window.id === tab.windowId) - return tab.active && window.focused - }) - .map(({ id, title, url }) => { - const { host } = new URL(url) - return { id, title, host } - }) + try { + const tabs = await browser.tabs.query({}) + const windows = await browser.windows.getAll() + const active = tabs + .filter((tab) => { + const window = windows.find((window) => window.id === tab.windowId) + return tab.active && window.focused + }) + .map(({ id, title, url }) => { + const { host } = new URL(url) + return { id, title, host } + }) - await Promise.all( - active.map(({ host }) => { - if (host) - return insertLog({ - timestamp: normalizeTimestamp(new Date()), - host, - seconds: (frequency / 1000) | 0, - }) - }) - ) + await Promise.all( + active.map(({ host }) => { + if (host) + return insertLog({ + timestamp: normalizeTimestamp(new Date()), + host, + seconds: (frequency / 1000) | 0, + }) + }) + ) + } catch {} } setInterval(() => {