-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
No handler registered in 'background' error, but background handler still being found and invoked #69
Comments
Hey, just ran into this issue myself, it seems like in bundle there are both .js and .cjs files from this package. It can be a problem because of webpack / babel configuration, that forces to use commonjs instead of es6 modules. But sideEffects can be tricky
in your tsconfig.ts. It also will force to use only es6 module resolution |
Thank you for your response, I have been waiting to get some time to learn and play around. Tonight I have spent a few hours playing around with my tsconfig and Vite bundler settings, and nothing has changed unfortunately. I also tested setting Here are my latest configurations maybe you might have some more insight {
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"compilerOptions": {
"target": "es2020",
"useDefineForClassFields": true,
"module": "es2020",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
}
} And my vite.config.js build settings (I removed the server configs for brevity) I just added the build target value to vite for testing, but did not originally set it. plugins: [ vue() ],
build: {
cssCodeSplit: true,
rollupOptions: {
plugins: [],
},
target: "es2020",
},
optimizeDeps: {
exclude: ['']
},
css: {
postcss: postcss
}, |
So I have been messing around a bit more. I downloaded the latest master branch into my local source tree and built it locally. I was able to do some more tracing. Only when tracing, I can catch the following exceptions, and see the promise being rejected with the screenshot below. Without the debugger attached, the promises returned from |
I encountered the same issue today and found the root cause - using enums for message IDs, like this: sendMessage(ACTION.REQUEST_POPUP_DATA) When I replaced the enum with a plain string value, everything started working without errors. Later, I realized there was a listener registered for an undefined message ID because the enum itself was undefined. Switching to string values resolved the issue. |
I have same problem: when option/sidepanel page is open, content-script ---> background will throw Error: [webext-bridge] No handler registered in 'background' to accept messages with id '...'. |
I migrated away from webext-bridge and wrote my own message handling code for my project, as I could not get passed this issue. You can see the code here it's agpl so it may not be the most friendly to your project, but maybe it can help you get your projects going. |
So, I recently ran into a fun new issue I am having a hard time debugging. I recently switched up from using "hard-coded" message handlers to generating them dynamically at runtime. Not a single issue passing messages until that change. (Ill explain)
The background onMessage handler for that messageId is correctly registered and is actually being called despite that error in the foreground code.
Error conditions
I was having issues tracing with the debugger from the background side (couldn't repro), however I could trace with console messages to determine that the functions were still getting called despite the error and failure. However the sendMessage console error appears after the method is called, but before the promise resolves.
Example Source Code
Each script, popup/options/conent-script pass the correct
sendMessage
function to theuseForegoundFeatures
method. ThesenMessage
function uses the default context argument (tried explicitly setting 'background' and doesnt change).Extra steps I have taken
After debugging, it seems fairly obvious that a promise is not being properly awaited, I just need to figure out where, and why it would cause that type of exception. Big apologies if this a bonehead mistake, I have just been pulling my hair out all weekend and was hoping someone might be able to help. I have not pushed these latest changes to my repo yet (I wanted to debug first) but I can create a buggy branch if it would help seeing the entire project.
The text was updated successfully, but these errors were encountered: