isaurssaurav / hot-reload-extension-vite-plugin

Simple vite plugin to reload chrome extension on file change.
MIT License
21 stars 4 forks source link

chrome.runtime.onStartup && chrome.runtime.onInstalled undefined in content.js #11

Closed dzgcsmthmt closed 1 month ago

dzgcsmthmt commented 2 months ago

in background and panel index.js,it is ok,but in content.js,chrome.runtime.onStartup && chrome.runtime.onInstalled undefined

dzgcsmthmt commented 2 months ago

config: hotReloadExtension({ log: true, backgroundPath: 'src/pages/content/index.ts' }), error

isaurssaurav commented 2 months ago

Hey @dzgcsmthmt,

backgroundPath in config should always point to service worker file. It is where reload function is injected.

As for the content script to reload, You should build the content script file on the vite.config.ts where you have hot-reload-extension-vite-plugin initialised with backgroundPath pointing to service worker file. Then, the plugin will detect change in content script file and reload the extension.

Here is the example where reloading in content script works. Please check vite.config.ts on this example project.

There may be some complex scenario which this plugin might not have covered. If so, I am happy to extend as required.