0

In JavaScript, once I've received a 'message' event, is there a way to find out which frame in the DOM model has initiated it? This would be helpful when debugging a large web application where a particular message could have come anyone of 15-20 frames. The message event has a source property, but if the frame is cross-domain, it's not accessible:

enter image description here

Since I know these things vary from browser to browser, I'm asking specifically about IE11.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • Is IE 11 still legal nowadays? – marekful Jun 14 '18 at 09:48
  • Will this help: https://stackoverflow.com/questions/21070553/postmessage-still-broken-on-ie11 – Asons Jun 14 '18 at 09:56
  • No, I'm well aware of that question, but what I want is to find out the identity of the frame which sent out a given message. Well, tbh I would prefer, when I have a breakpoint in a message handler, to be able to jump to the line of code which issued the postMessage() which caused this event, but even the identity of the frame would be enough. – sashoalm Jun 14 '18 at 10:43

1 Answers1

0

I found a way that actually works even when cross-domain - I add a DOM element by evaluating it in the Add Watch window. Then I search the DOM tree for that element, and figure out the frame in this way.

For example, this code works:

var foo_btn = document.createElement("BUTTON"); var foo_t = document.createTextNode("FOOBAR FOOBAR"); foo_btn.appendChild(foo_t); document.body.appendChild(foo_btn);

You just click Add Watch and paste it, and then after it executes, you can search for FOOBAR FOOBAR in the DOM tree.

enter image description here

sashoalm
  • 75,001
  • 122
  • 434
  • 781