Closed
Bug 1108410
Opened 8 years ago
Closed 8 years ago
Event listener for customEvent doesnt fire in frame scripts
Categories
(Core :: DOM: Events, defect)
Tracking
()
RESOLVED
INVALID
Tracking | Status | |
---|---|---|
e10s | ? | --- |
People
(Reporter: micha.postbox, Assigned: jimm)
References
Details
Attachments
(1 file)
2.40 KB,
application/x-xpinstall
|
Details |
User Agent: Mozilla/5.0 (Windows NT 6.3; rv:37.0) Gecko/20100101 Firefox/37.0 Build ID: 20141206030202 Steps to reproduce: Added evtentlistener to my frame.js due making tests for E10s migration for my bootstrap addon. //addon code with setup of messageManager & loading the frame script let browserMM = gBrowser.selectedBrowser.messageManager; ... if(!gBrowser.selectedBrowser.editorFrameScriptLoaded) { browserMM.loadFrameScript("chrome://myaddon/content/frame.js", true); gBrowser.selectedBrowser.editorFrameScriptLoaded = true; } Actual results: //frame.js //addonEvent is a data container event and fires if 4th parameter is set addEventListener("addonEvent", function(evt) {console.log('testa: ' + evt)}, false, true); //context-message is a customEvent and event listener fires not here addEventListener("context-message", function(evt) {console.log('testb: ' + evt)}, false, true); Expected results: Custom events should be detected by event listener in frame scripts, as it is the case for datacontainer events.
Updated•8 years ago
|
Component: Untriaged → DOM: Events
Product: Firefox → Core
Comment 1•8 years ago
|
||
Can you easily provide an XPI to test this with?
-Install testcase -go to https://bugzilla.mozilla.org/ -2 Buttons are added below on page -output on console is missing for custom events At the moment i use datacontainer events to call frame script functions. But this is depreciated.
Flags: needinfo?(micha.postbox)
Comment 4•8 years ago
|
||
So you dispatch non-bubbling event, but add event listener to bubble phase.
Comment 5•8 years ago
|
||
Try new CustomEvent("custom-event", {bubbles: true, "detail":{"id": this.getAttribute("id")}});
Yes! This works. But for old style addons without framescripts this "bubble" was not necessary. It was detected without the bubble set to true. Why do we have events which are not bubble? "but add event listener to bubble phase." Is there also still a secret switch for event listener for non bubbling events? Please update MDN: https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent Thank you.
Comment 7•8 years ago
|
||
(In reply to TheRave from comment #6) > Yes! This works. But for old style addons without framescripts this "bubble" > was not necessary. It was detected without the bubble set to true. Do you have some example code. frame scripts or e10s don't affect to how events bubble or not. > Why do we have events which are not bubble? Events don't bubble by default. See the specification https://dom.spec.whatwg.org/#interface-event > Please update MDN: > https://developer.mozilla.org/en-US/docs/Web/Guide/Events/ > Creating_and_triggering_events > https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent MDN is a wiki. Feel free to update it :)
Comment 8•8 years ago
|
||
(In reply to Olli Pettay [:smaug] from comment #7) > > Please update MDN: > > https://developer.mozilla.org/en-US/docs/Web/Guide/Events/ > > Creating_and_triggering_events > > https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent > MDN is a wiki. Feel free to update it :) ... because it is not quite clear to me what you want to be updated.
You are right, its not E10s related. But it is chrome code related and there are differences to frame scripts. I have still a working "example" code in my "chrome part" of my addon: menutItem.setAttribute("oncommand","var event = new CustomEvent('context', {'detail':{'context_1': this.getAttribute('label')}}); document.defaultView.dispatchEvent(event);"); ..... window.addEventListener("context", myNamespace.contextAction, false); I use this code to get data from my click event on context menu into contextAction(), where additional actions will be done. It works exactly as written above, without bubble settings. Also with actual nightly. What should be updated on MDN is that there are no hints to the bubble settings. There is an example with a mouse click below on MDN page. But i have not checked that this could be somehow important. No further explanation what bubbles: true does there, only the code. The other examples there have the bubbles stuff also not. Its new for me that everyone can update MDN.
Comment 10•8 years ago
|
||
(In reply to TheRave from comment #9) > You are right, its not E10s related. But it is chrome code related and there > are differences to frame scripts. > > I have still a working "example" code in my "chrome part" of my addon: > > menutItem.setAttribute("oncommand","var event = new CustomEvent('context', > {'detail':{'context_1': this.getAttribute('label')}}); > document.defaultView.dispatchEvent(event);"); > > ..... > > window.addEventListener("context", myNamespace.contextAction, false); If this all happens in the same page, document.defaultView == window. Then when the event listener is called the event is in AT_TARGET phase, not in capture nor in bubble and all the listeners for the event are called. Again, per the specification https://dom.spec.whatwg.org/#dispatching-events
Reporter | ||
Comment 11•8 years ago
|
||
Finally after reading this page http://www.w3.org/TR/DOM-Level-3-Events/#event-flow i understand your last comment and the different event flows. We can close this bug. Thank you for support.
Updated•8 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•