-
-
Notifications
You must be signed in to change notification settings - Fork 287
fix(security): Use import.meta.hot
for communication with Vite 6.0.9+ (and 5.4.14+) dev server
#1411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(security): Use import.meta.hot
for communication with Vite 6.0.9+ (and 5.4.14+) dev server
#1411
Changes from 13 commits
9bdeb1a
6d5fdcc
bebb8c9
d213951
84d0839
51a16fe
63335dc
1e7f540
7af3cc6
a49463f
c46a5ca
91941ff
37b4124
d815ebf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,23 @@ export function devServerGlobals( | |
return { | ||
name: 'wxt:dev-server-globals', | ||
config() { | ||
if (server == null || config.command == 'build') return; | ||
if (server == null || config.command == 'build') | ||
return { | ||
define: { | ||
__WXT_BACKGROUND_CLIENT_IMPORT__: '', | ||
}, | ||
}; | ||
|
||
const wxtBackgroundClientUrl = `http://${server.hostname}:${server.port}/@id/wxt/background-client`; | ||
console.log({ wxtBackgroundClientUrl }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO remove |
||
|
||
return { | ||
define: { | ||
__WXT_BACKGROUND_CLIENT_IMPORT__: JSON.stringify( | ||
config.manifestVersion === 2 | ||
? `import(/* @vite-ignore */ "${wxtBackgroundClientUrl}")` | ||
: `/* @vite-ignore */\nimport "${wxtBackgroundClientUrl}"`, | ||
), | ||
__DEV_SERVER_PROTOCOL__: JSON.stringify('ws:'), | ||
__DEV_SERVER_HOSTNAME__: JSON.stringify(server.hostname), | ||
__DEV_SERVER_PORT__: JSON.stringify(server.port), | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,8 @@ | ||
import definition from 'virtual:user-background-entrypoint'; | ||
import { initPlugins } from 'virtual:wxt-plugins'; | ||
import { getDevServerWebSocket } from '../sandbox/dev-server-websocket'; | ||
import { logger } from '../sandbox/utils/logger'; | ||
import { browser } from 'wxt/browser'; | ||
import { keepServiceWorkerAlive } from './utils/keep-service-worker-alive'; | ||
import { reloadContentScript } from './utils/reload-content-scripts'; | ||
|
||
if (import.meta.env.COMMAND === 'serve') { | ||
try { | ||
const ws = getDevServerWebSocket(); | ||
ws.addWxtEventListener('wxt:reload-extension', () => { | ||
browser.runtime.reload(); | ||
}); | ||
ws.addWxtEventListener('wxt:reload-content-script', (event) => { | ||
reloadContentScript(event.detail); | ||
}); | ||
|
||
if (import.meta.env.MANIFEST_VERSION === 3) { | ||
// Tell the server the background script is loaded and ready to go | ||
ws.addEventListener('open', () => | ||
ws.sendCustom('wxt:background-initialized'), | ||
); | ||
|
||
// Web Socket will disconnect if the service worker is killed | ||
keepServiceWorkerAlive(); | ||
} | ||
} catch (err) { | ||
logger.error('Failed to setup web socket connection with dev server', err); | ||
} | ||
|
||
browser.commands.onCommand.addListener((command) => { | ||
if (command === 'wxt:reload-extension') { | ||
browser.runtime.reload(); | ||
} | ||
}); | ||
} | ||
console.log('__WXT_BACKGROUND_CLIENT_IMPORT__'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: Remove |
||
__WXT_BACKGROUND_CLIENT_IMPORT__; | ||
|
||
let result; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,6 @@ | ||
import { logger } from '../sandbox/utils/logger'; | ||
import { getDevServerWebSocket } from '../sandbox/dev-server-websocket'; | ||
|
||
if (import.meta.env.COMMAND === 'serve') { | ||
try { | ||
const ws = getDevServerWebSocket(); | ||
ws.addWxtEventListener('wxt:reload-page', (event) => { | ||
// "popup.html" === "/popup.html".substring(1) | ||
if (event.detail === location.pathname.substring(1)) location.reload(); | ||
}); | ||
} catch (err) { | ||
logger.error('Failed to setup web socket connection with dev server', err); | ||
} | ||
if (import.meta.hot) { | ||
import.meta.hot.on('wxt:reload-page', (event) => { | ||
// "popup.html" === "/popup.html".substring(1) | ||
if (event.detail === location.pathname.substring(1)) location.reload(); | ||
}); | ||
} | ||
Comment on lines
+1
to
6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: Test |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.