Skip to content

Commit

Permalink
Debug Logs
Browse files Browse the repository at this point in the history
This is to help diagnose some issues with Arc Browser. Turned off by default.
  • Loading branch information
sethcottle committed May 8, 2023
1 parent 1ff0cd8 commit 78a4436
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
53 changes: 51 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const DEBUG = false;

function debugLog(message) {
if (DEBUG) {
console.log(message);
}
}

const predefinedUrlPatterns = [
{
label: ' Zoom Joins',
Expand Down Expand Up @@ -29,14 +37,17 @@ function shouldCloseTab(url) {
}
const shouldClose = predefinedUrlPatterns.some(({ pattern }) => {
const regex = new RegExp(pattern, 'i');
return regex.test(url) && !disabledUrls.includes(pattern);
const matches = regex.test(url);
debugLog(`Testing URL ${url} against pattern ${pattern}: ${matches}`);
return matches && !disabledUrls.includes(pattern);
});
resolve(shouldClose);
});
});
}

async function checkTab(tab) {
debugLog(`Checking tab with ID ${tab.id} and URL ${tab.url}`);
const shouldClose = await shouldCloseTab(tab.url);
if (shouldClose) {
try {
Expand All @@ -50,9 +61,12 @@ async function checkTab(tab) {
}
});
});
debugLog(`Tab with ID ${tab.id} and URL ${tab.url} closed`);
} catch (error) {
console.log(`Error closing tab with id ${tab.id}:`, error.message);
console.error(`Error closing tab with id ${tab.id}:`, error.message);
}
} else {
debugLog(`Tab with ID ${tab.id} and URL ${tab.url} not closed`);
}
}

Expand All @@ -71,5 +85,40 @@ function processTabs(tabs, index, interval) {

chrome.storage.sync.get(['interval'], ({ interval }) => {
interval = interval || 30;
debugLog(`Using check interval: ${interval} seconds`);
chrome.tabs.query({}, (tabs) => processTabs(tabs, 0, interval));
});

let checkInterval;

function processTabs(tabs, index) {
if (index >= tabs.length) {
console.log('All tabs processed. Waiting for the next interval:', checkInterval); // Added debug log
setTimeout(() => {
chrome.tabs.query({}, (tabs) => processTabs(tabs, 0));
}, checkInterval * 1000);
return;
}

const tab = tabs[index];
console.log('Checking tab:', tab.url); // Added debug log
checkTab(tab);
processTabs(tabs, index + 1);
}

chrome.storage.sync.get(['interval'], ({ interval }) => {
checkInterval = interval || 30;
console.log('Initial check interval:', checkInterval); // Added debug log
chrome.tabs.query({}, (tabs) => processTabs(tabs, 0));
});

// Add this event listener to listen for storage changes
chrome.storage.onChanged.addListener((changes, areaName) => {
if (areaName === 'sync' && changes.interval) {
checkInterval = changes.interval.newValue;
console.log('Check interval updated:', checkInterval); // Added debug log
} else {
console.log('No change in check interval detected'); // Added debug log
}
});

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "TabCloser",
"version": "2.1.1",
"version": "2.1.6",
"description": "Automatically close redirected Figma, Zoom, Spotify, VS Code Live Share, and Discord tabs.",
"action": {
"default_popup": "popup.html",
Expand Down
14 changes: 8 additions & 6 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,25 @@ function renderCheckboxes() {
}

function loadCheckInterval() {
chrome.storage.sync.get(['checkInterval'], ({ checkInterval }) => {
if (!checkInterval) {
checkInterval = 30;
chrome.storage.sync.get(['interval'], ({ interval }) => {
if (!interval) {
interval = 30;
}
const checkIntervalInput = document.getElementById('check-interval');
checkIntervalInput.value = checkInterval;
checkIntervalInput.value = interval;
console.log('Loaded check interval:', interval); // Added debug log
checkIntervalInput.addEventListener('input', () => {
const newValue = parseInt(checkIntervalInput.value, 10);
if (newValue > 0) {
chrome.storage.sync.set({ checkInterval: newValue }, () => {
console.log('Check interval saved');
chrome.storage.sync.set({ interval: newValue }, () => {
console.log('Check interval saved:', newValue); // Added debug log
});
}
});
});
}


document.addEventListener('DOMContentLoaded', () => {
renderCheckboxes();
loadCheckInterval();
Expand Down

0 comments on commit 78a4436

Please sign in to comment.