Build issue: ERROR Browser.runtime.onConnect.addListener not implemented. 10:06:24
thomasf1 opened this issue · 4 comments
Describe the bug
Adding webext-bridge/background leads to a build error. It seems there is some testing going on but the used fake-browser library is a bit overdramatic and trows an error because it hasn´t got that part of the fake browser covered yet?
Reproduction
Adding webext-bridge/background leads to a build error:
✖ Command failed after 359 ms 02:52:53
ERROR Browser.runtime.onConnect.addListener not implemented. 02:52:53
Mock the function yourself using your testing framework, or submit a PR with an in-memory implementation.
Mock the function yourself using your testing framework, or submit a PR with an in-memory implementation.
at Object.addListener (node_modules/.pnpm/@webext-core+fake-browser@1.3.1/node_modules/@webext-core/fake-browser/lib/index.js:4387:15)
at node_modules/.pnpm/webext-bridge@6.0.1/node_modules/webext-bridge/dist/background.js:154:27
at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)
at ViteNodeRunner.interopedImport (node_modules/.pnpm/vite-node@2.1.4_@types+node@22.8.2/node_modules/vite-node/dist/client.mjs:421:28)
at ViteNodeRunner.directRequest (node_modules/.pnpm/vite-node@2.1.4_@types+node@22.8.2/node_modules/vite-node/dist/client.mjs:280:24)
at ViteNodeRunner.cachedRequest (node_modules/.pnpm/vite-node@2.1.4_@types+node@22.8.2/node_modules/vite-node/dist/client.mjs:206:14)
at ViteNodeRunner.dependencyRequest (node_modules/.pnpm/vite-node@2.1.4_@types+node@22.8.2/node_modules/vite-node/dist/client.mjs:259:12)
at entrypoints/background.js:3:31
at ViteNodeRunner.runModule (node_modules/.pnpm/vite-node@2.1.4_@types+node@22.8.2/node_modules/vite-node/dist/client.mjs:399:5)
Steps to reproduce
Adding the following to the background script:
import { onMessage, sendMessage, allowWindowMessaging } from "webext-bridge/background"
(compiles ok)
and then using it (onmessage) or
allowWindowMessaging('mynamespace')
(or)
onMessage("test1", (params) => {
console.log('test1 background', params);
return 'hey from test1 background'; //loadUserPreferences(sync);
});
System Info
Here the installed packages:
@wxt-dev/auto-icons 1.0.2
typescript 5.6.3
webext-bridge 6.0.1
wxt 0.19.13
Used Package Manager
pnpm
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
The thing I don´t get about it: As it´s mentioned in the docs, a fair bit of WXT users should also use webext-bridge. I´m trying some stripped down examples now, but even a minimal background.js doesn´t work:
import { onMessage, sendMessage, allowWindowMessaging } from "webext-bridge/background"
allowWindowMessaging('xxx');
Move allowWindowMessaging('xxx');
into the main function?
Can you share the output of wxt prepare --debug
?
Move
allowWindowMessaging('xxx');
into the main function?
How stupid of me, that did it. Just mentally stuck to some example code for some reason