initCustomEvent pass data for method doesn't work anymore

前端 未结 2 427
忘掉有多难
忘掉有多难 2021-01-29 01:58

I wrote a firefox extension and for interation data between privilege and non-privilege pages I use this snipped code

    //Listen for the event
    window.addE         


        
相关标签:
2条回答
  • 2021-01-29 02:22

    You probably have to use __exposedProps__.

    Like

    var detail = {
      name: "activate",
      method: function(){},
      __exposedProps__: {method: "r"}
    };
    

    Needless to say that, unless you are absolutely sure that you know what you 're doing, this is a security risk.

    0 讨论(0)
  • 2021-01-29 02:35

    Are you sure things used to work before?

    You need to set the 4th argument of addEventListener to true. Argument is called wantsUntrusted.

    MDN :: addEventListener

    Also see this topic here: How to listen to custom events on all windows, bubbling issue?

    So try this:

    //Listen for the event
    window.addEventListener("MyEvent", function(evt) {
        console.log(evt.detail);
    }, false, true);
    
    //Dispatch an event
    var evt = document.createEvent("CustomEvent");
    evt.initCustomEvent("MyEvent", true, true, {
      name : 'activate',
      method : function() {
        //...
      }    
    });
    window.dispatchEvent(evt);
    
    0 讨论(0)
提交回复
热议问题