You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dev mode: reconnect the background's dev-server WebSocket after it closes #2707
In dev mode, the background script reconnects to the dev server after its WebSocket closes.
With webExt: { disabled: true } (Chrome ignores --load-extension, so the dev build is loaded unpacked by hand), the extension outlives each wxt dev run. getDevServerWebSocket in packages/wxt/src/utils/internal/dev-server-websocket.ts opens the socket once; on close it only logs "Disconnected from dev server", and ws keeps the closed socket, so the background never connects again. After a dev-server restart or a dropped socket, every later build reaches nobody, and hot reload stops until the extension is reloaded by hand at chrome://extensions.
Proposal: on close, the background probes the dev server every few seconds. When it answers, the background calls browser.runtime.reload(), and the fresh background reloads the tabs its content scripts match, because the reload cuts their content scripts off from the extension. We run this today as a patch of dist/virtual/background-entrypoint.mjs on 0.21.5 (about 30 lines, dev build only).
Is your feature request related to a bug?
N/A
What are the alternatives?
Reconnect the socket in place and attach the listeners again: builds made while the socket was down are lost, so the extension can run stale code until the next edit.
Reload the extension by hand after each dev-server restart: what users do today.
Additional context
wxt 0.21.5, Chrome on macOS. The main branch has the same dev-server-websocket.ts code.
One more detail from running the patch: the fresh background has to know that it should reload the tabs, so a flag has to survive browser.runtime.reload(). We keep it in browser.storage.local, which needs the storage permission; in an extension that does not ask for it, the write throws and the reload never happens. WXT already adds tabs and scripting to the dev manifest, so adding storage in dev too would keep the reconnect working for every extension.
Thanks for looking into this! It's not the same: #1454 asked for docs on developing with or without the runner, and #2715 covers that. This issue asks for the background to reconnect by itself.
The tip helps as a workaround, since Alt + R brings hot reload back without opening chrome://extensions. It still has to be pressed after every restart or dropped socket, and nothing shows that the extension has stopped receiving builds, so stale code is easy to miss.
This is the reconnect part of the patch I run on 0.21.5, in dist/virtual/background-entrypoint.mjs:
letreconnecting=false;functionreloadWhenDevServerReturns(){if(reconnecting)return;reconnecting=true;consttimer=setInterval(()=>{constprobe=newWebSocket(__DEV_SERVER_ORIGIN__,"vite-hmr");probe.addEventListener("open",()=>{clearInterval(timer);probe.close();browser.runtime.reload();});},2e3);}// in the `import.meta.env.COMMAND === "serve"` blockconstws=getDevServerWebSocket();ws.addEventListener("close",reloadWhenDevServerReturns);
One correction to my earlier comment: the storage permission is not needed in MV3. After runtime.reload(), the fresh background sends wxt:background-initialized, and WXT then registers the content scripts and reloads their tabs.
#2750 is the direction this issue asks for, thank you!
Activity
denkasyanov commentedon Oct 31, 2026
One more detail from running the patch: the fresh background has to know that it should reload the tabs, so a flag has to survive
browser.runtime.reload(). We keep it inbrowser.storage.local, which needs thestoragepermission; in an extension that does not ask for it, the write throws and the reload never happens. WXT already addstabsandscriptingto the dev manifest, so addingstoragein dev too would keep the reconnect working for every extension.fkatsuhiro commentedon Nov 5, 2026
Hi, @denkasyanov san
Thank you reporting! Is this issue is same as #1454 ?
I've added workaround in documentation as tips. Could you take a look and see if it helps?
https://wxt.dev/guide/essentials/config/browser-startup.html#disable-opening-browser
Thanks!
fkatsuhiro commentedon Nov 14, 2026
Let me investigate auto-connect feature solution. Thanks.
denkasyanov commentedon Nov 24, 2026
Thanks for looking into this! It's not the same: #1454 asked for docs on developing with or without the runner, and #2715 covers that. This issue asks for the background to reconnect by itself.
The tip helps as a workaround, since
Alt + Rbrings hot reload back without openingchrome://extensions. It still has to be pressed after every restart or dropped socket, and nothing shows that the extension has stopped receiving builds, so stale code is easy to miss.This is the reconnect part of the patch I run on 0.21.5, in
dist/virtual/background-entrypoint.mjs:One correction to my earlier comment: the
storagepermission is not needed in MV3. Afterruntime.reload(), the fresh background sendswxt:background-initialized, and WXT then registers the content scripts and reloads their tabs.#2750 is the direction this issue asks for, thank you!