fix: Ensure content scripts are registered immediately in dev mode (#1253)

This commit is contained in:
Aaron
2024-12-05 18:16:38 -06:00
committed by GitHub
parent 17af05acc8
commit 88f126e658
+6 -4
View File
@@ -97,15 +97,17 @@ async function createServerInternal(): Promise<WxtDevServer> {
wxt.logger.success(`Started dev server @ ${server.origin}`);
await wxt.hooks.callHook('server:started', wxt, server);
await buildAndOpenBrowser();
// Register content scripts for the first time after the background starts up since they're not
// listed in the manifest
// Register content scripts for the first time after the background starts
// up since they're not listed in the manifest.
// Add listener before opening the browser to guarentee it is present when
// the extension sends back the initialization message.
server.ws.on('wxt:background-initialized', () => {
if (server.currentOutput == null) return;
reloadContentScripts(server.currentOutput.steps, server);
});
await buildAndOpenBrowser();
// Listen for file changes and reload different parts of the extension accordingly
const reloadOnChange = createFileReloader(server);
server.watcher.on('all', reloadOnChange);