fix this edge & chrome extension code ,manifest v3 , error "Service worker registration…
- User
fix this edge & chrome extension code ,manifest v3 , error "Service worker registration failed. Status code: 15 ( "service_worker": "background.js" )" ,and second error "Uncaught TypeError: Cannot read properties of undefined (reading 'onCompleted')
Context
extension://kkkjdafeljpfdoocejlnikmfdbblcoai/background.js
Stack Trace
background.js:76 (anonymous function) (chrome.webNavigation.onCompleted.addListener(async (details) => { )" ,this is full code of background.js "let currentlyPlayingTabId = null; const closeTimers = {}; // Map of tabId to close timer data const closeDuration = 10000; // 10 seconds
// Listener for the extension icon click to pause all videos chrome.action.onClicked.addListener((tab) => { chrome.tabs.query({}, (tabs) => { tabs.forEach((tab) => { chrome.tabs.sendMessage(tab.id, { action: 'pauseAllVideos' }); }); }); });
// Updates the red progress bar and closes the tab when complete const updateRedBarProgress = (tabId) => { const timerData = closeTimers[tabId]; if (!timerData) return;
const { closeStartTime } = timerData; const elapsedTime = Date.now() - closeStartTime; const progress = Math.min((elapsedTime / closeDuration) * 100, 100);
chrome.tabs.sendMessage(tabId, { action: 'updateRedBarProgress', progress: progress });
if (progress < 100) { timerData.closeTimerId = setTimeout(() => updateRedBarProgress(tabId), 100); // Update every 100ms } else { chrome.tabs.remove(tabId, () => { if (chrome.runtime.lastError) { console.error(
Error closing tab: ${chrome.runtime.lastError.message}); } }); delete closeTimers[tabId]; } };// Message handler from content scripts chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { const tabId = sender.tab.id; switch (request.action) { case 'videoStartedPlaying': if (currentlyPlayingTabId && currentlyPlayingTabId !== tabId) { chrome.tabs.sendMessage(currentlyPlayingTabId, { action: 'pauseAllVideos' }); } currentlyPlayingTabId = tabId; break; case 'videoStoppedPlaying': if (tabId === currentlyPlayingTabId) { currentlyPlayingTabId = null; } break; case 'startCloseTimer': if (closeTimers[tabId]) { clearTimeout(closeTimers[tabId].closeTimerId); } closeTimers[tabId] = { closeStartTime: Date.now(), closeTimerId: null, }; if (sender.tab.url.includes('youtube.com')) { updateRedBarProgress(tabId); } break; case 'cancelCloseTimer': if (closeTimers[tabId]) { clearTimeout(closeTimers[tabId].closeTimerId); delete closeTimers[tabId]; } break; } sendResponse({ status: 'Message received' }); return true; });
// Listen for webNavigation events to inject content script into iframes chrome.webNavigation.onCompleted.addListener(async (details) => { if (details.frameId !== 0) { // It's an iframe try { await chrome.scripting.executeScript({ target: { tabId: details.tabId, frameIds: [details.frameId] }, files: ['content.js'], }); } catch (e) { console.error('Failed to inject script into iframe:', e); } } });" , content.js "let currentlyPlaying = null; let lastUserInteractionTime = 0; let videoElements = new WeakSet(); let lastTitle = document.title;
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.