Browser extensions and event emitters
Hey, anyone here familiar with browser extensions and event emitters? I have two questions:
-
Can different extensions emit the same eventListener? Let's say I want a website to listen to 'extensions' event, could different browser extensions emit and use the same name?
-
Can these extensions send information through this event? Like a js object?
So I would like to trigger from the website something like
window.addEventListener('extensions', (extensionInfo)=>{
numOfExtensions =+ 1;
console.log(extensionInfo)
})
Not sure if this is possible or if there would be a conflict between the extensions when triggering emit.
Thanks
Posted May 2, 2023, 5:15 AM UTC
24
Here are the answers
Here is an example
And in the top context
Thanks a lot for the answer, I have one last question, let's say this extensions are competing each other, would it be possible for one extension to cheat and stop or prevent others from using the emitter?
Possible if the event being dispatched is cancellable (the cancellable option should be defined on every CustomEvent being dispatched) but it's not a feasible solution as it results in race conditions since the extensions are not always loaded in the same order and could result in unexpected behavior.
It's not a tested answer btw.