Skip to content

Fix 6 bugs: tab hijacking, cache expiry, NaN settings, debugger error handling#2

Draft
Copilot wants to merge 1 commit intomainfrom
copilot/fix-tab-capture-crash-risk
Draft

Fix 6 bugs: tab hijacking, cache expiry, NaN settings, debugger error handling#2
Copilot wants to merge 1 commit intomainfrom
copilot/fix-tab-capture-crash-risk

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 27, 2026

Six independent bugs in background.js and popup.js ranging from crashes to silent data corruption.

background.js

  • getTabId() crash + tab hijacking: tabs[0] was accessed unconditionally — undefined when no active tab exists (auto-start alarm). Now falls back to chrome.tabs.create({ active: false }) to avoid hijacking the user's current tab and to prevent the TypeError.

  • onConnect popup-close handler: On popup disconnect, code re-queried the current active tab to detach the debugger — wrong tab entirely. Now uses searchState.tabId directly; no-ops if null.

  • trendingWordsCache never expired: Cached value was a bare array with no timestamp, surviving the full service worker lifetime regardless of TRENDS_CACHE_DURATION. Now stored as { terms, timestamp } with expiry checked on every read.

  • Unhandled chrome.runtime.lastError: enableDebugger/disableDebugger didn't read lastError in their callbacks, producing unchecked-error console noise when a tab was closed mid-search. Both now handle it.

  • randomDelay() with inverted min/max: If user sets max < min, max - min goes negative. Fixed with Math.min/Math.max normalization:

    const lo = Math.min(min, max);
    const hi = Math.max(min, max);
    return Math.floor(Math.random() * (hi - lo + 1) + lo);

popup.js

  • NaN from empty form fields: parseInt("") returns NaN, which propagates into totalSearches and breaks progress math. Added || default fallbacks on every parseInt() call in both sendAutoStartSettingsToBackground() and startSearches().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants