Changes in background script files are not picked by the manifest V3 browser extension

245 views
Skip to first unread message

Vinod Kumar

unread,
Feb 27, 2025, 1:51:53 PMFeb 27
to Chromium Extensions
Hi,

 Any changes made in the background script files are not reflecting in the installed extension in the browser. We have to reload or update the extension from "chrome://extensions" page manually. How can I make the extension to load the latest background script files always?

woxxom

unread,
Feb 27, 2025, 5:51:50 PMFeb 27
to Chromium Extensions, Vinod Kumar
One workaround would be to use the new FileSystemObserver API to track changes or just periodically poll the file:// URL for your background script inside the offscreen document, for example, and when a change is detected send a message so that onMessage handler will call chrome.runtime.reload()

The problem is an inherent design flaw of ManifestV3, one of many, because the background script is now a service worker, which ideally should have improved performance (in 99.9999% of cases it didn't) or security (no change) or interoperability/similarity with the web platform code (there's none). The actual code of the service worker is stored in a special internal database, which is updated only when you install/update/reload the extension. This is also super inconvenient when you have tabs/popups of your extension open as reloading closes everything and you have to re-open and re-navigate everything. 

Oliver Dunk

unread,
Feb 28, 2025, 6:10:18 AMFeb 28
to woxxom, Chromium Extensions, Vinod Kumar
As well as the methods wOxxOm mentioned, you can also run `chrome.runtime.reload()` in the service worker window. That's my personal go-to.

I do still want us to see CTRL / CMD + R come back to DevTools which isn't incompatible with the design of Manifest V3 and would make the experiences much more similar.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/edc6ab68-b4d4-422d-ac8a-d68ccae85ea0n%40chromium.org.

Vinod Kumar

unread,
Mar 3, 2025, 1:20:29 PMMar 3
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Vinod Kumar, woxxom
I have added chrome.runtime.reload() to reload the extension inside the service worker.

if(Condition to reload extension) {
    chrome.runtime.reload();
} else {
    importAllScripts();
}

To prevent background scripts from being imported while reloading the extension, the importScripts () code was moved into a function. But I am getting the following error related to WorkerGlobalScope. 

function importAllScripts() {
importScripts("backgroundscript1.js"); - Failing at this line with this error - Error handling response: NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at '
importScripts("backgroundscript2.js");
importScripts("backgroundscript3.js");  
}

I found a bug related to postponed importscripts - https://issues.chromium.org/issues/40760920
Reply all
Reply to author
Forward
0 new messages