← back to Govarbitrage

extension/background.js

29 lines

/**
 * GovArbitrage Capture — MV3 service worker.
 *
 * Intentionally minimal. The extension does its real work from the popup
 * (chrome.scripting + fetch), so this worker only:
 *   - logs install/update for debugging
 *   - optionally relays messages (kept for future content-script → app hooks)
 *
 * Service workers in MV3 are ephemeral; do not hold long-lived state here.
 */

chrome.runtime.onInstalled.addListener((details) => {
  console.log('[GovArbitrage Capture] installed/updated:', details.reason);
});

// Optional message relay. Not required for the current popup-driven flow, but
// lets a future content script ping the worker without breaking anything.
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
  try {
    if (message && message.type === 'PING') {
      sendResponse({ type: 'PONG', ts: Date.now() });
      return true; // keep the channel open for the async response
    }
  } catch (e) {
    console.warn('[GovArbitrage Capture] message handler error:', e);
  }
  return false;
});