console.log('Background script loaded'); let apiUrl = ''; chrome.webRequest.onBeforeSendHeaders.addListener( (details) => { console.log('Intercepted request:', details.url); const apiKeyHeader = details.requestHeaders.find(h => h.name === 'CH-API-KEY'); if (apiKeyHeader) { console.log('API Key found:', apiKeyHeader.value); chrome.storage.local.set({ apiKey: apiKeyHeader.value }); } if (details.url.includes('api.chub.ai/search')) { console.log('API URL found:', details.url); apiUrl = details.url; chrome.storage.local.set({ apiUrl: details.url }); } return { requestHeaders: details.requestHeaders }; }, { urls: ["https://api.chub.ai/*"] }, ["requestHeaders"] );