none
Edge Extension Custom events RRS feed

  • Question

  • Hi All,

    I have developed an extension that works across all browser with common javascript (including IE sandbox - but for IE I use postMessage in the particular case). My problem relates to the Edge browser. I have a web page that creates a custom event. In the extension "content" script I have a handler that captures the event and cause a set of functions to be executed. 

    // Web page
    var event = new Event('myCoolCustomEvent');
    document.dispatchEvent(event);
    
    // Extension Content script
      document.addEventListener('myCoolCustomEvent', 
    function(e) {
                    alert("whoa")
                }, false);

    All browsers (FF, Chrome) capture the custom event without issue. Does edge support a custom event from web page to content script? Is there a special premission I have to set within the manifest.

    Thanks,

    Tom


    • Edited by Thomas Lee3 Wednesday, June 13, 2018 7:19 PM
    Wednesday, June 13, 2018 7:17 PM

Answers

  • Hi Thomas Lee3,

    I try to make a test with code below in Edge.

    <!DOCTYPE HTML>
    <html>
    <head>
      <meta charset="utf-8">
    </head><body>
    
    <h1 id="elem">Hello from the script!</h1>
    
    <script>
      // catch on document...
      document.addEventListener("hello", function(event) { // (1)
        alert("Hello from " + event.target.tagName); // Hello from H1
      });
    
      // ...dispatch on elem!
      let event = new Event("hello", {bubbles: true}); // (2)
      elem.dispatchEvent(event);
    </script>
    
    </body>
    </html>

    Output:

    You can try to make a test with this code and let us know whether it work for you or not.

    We will try to provide further suggestions, If needed.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Thomas Lee3 Friday, June 15, 2018 1:26 PM
    Friday, June 15, 2018 7:58 AM
    Moderator

All replies

  • Hi Thomas Lee3,

    I try to make a test with code below in Edge.

    <!DOCTYPE HTML>
    <html>
    <head>
      <meta charset="utf-8">
    </head><body>
    
    <h1 id="elem">Hello from the script!</h1>
    
    <script>
      // catch on document...
      document.addEventListener("hello", function(event) { // (1)
        alert("Hello from " + event.target.tagName); // Hello from H1
      });
    
      // ...dispatch on elem!
      let event = new Event("hello", {bubbles: true}); // (2)
      elem.dispatchEvent(event);
    </script>
    
    </body>
    </html>

    Output:

    You can try to make a test with this code and let us know whether it work for you or not.

    We will try to provide further suggestions, If needed.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Thomas Lee3 Friday, June 15, 2018 1:26 PM
    Friday, June 15, 2018 7:58 AM
    Moderator
  • Hey Deepak,

    The bubbles parameter appears to work. It never ocurred to me to try that. Thanks for looking at that!

    Friday, June 15, 2018 1:25 PM