TraceKit icon indicating copy to clipboard operation
TraceKit copied to clipboard

TraceKit can now be used on frames

Open aquadk opened this issue 8 years ago • 14 comments

Hi, have made this change so, I only need to include TraceKit once on my frame page.

Here is the code for the frame page.

function insertTraceKit() {

  function yourLogger(errorReport) {
    console.log(errorReport);
    return true;
  }

  TraceKit.report.subscribe(yourLogger);

  function wrapped(aThis) {
    TraceKit.report.subscribe(yourLogger, aThis.target.contentWindow);
    try {
      aThis.target.contentWindow.onunload = unwrapped;
    } catch (e) {
      //console.log('cross-origin frame detected');
    }
  }

  function unwrapped(aThis) {
    TraceKit.report.unsubscribe(yourLogger, aThis.currentTarget);
  }

  var frames = document.getElementsByTagName('frame');
  for (var i = 0; i < frames.length; i++) {
    frames[i].onload = wrapped;
  };

}

var readyStateCheckInterval = setInterval(waitInit, 10, this);

function waitInit() {
  //console.log(document.readyState);
  if (document.readyState === "interactive") {
    clearInterval(readyStateCheckInterval);
    insertTraceKit();
  }
}

aquadk avatar Jan 17 '17 00:01 aquadk

Hi, Have now made the changes you asked for.

aquadk avatar Jan 18 '17 14:01 aquadk

I'm sorry for taking so long to get back to this. What is the current status of this?

niemyjski avatar Jun 29 '17 01:06 niemyjski

I have updated the code for Iframe page too.


   /**    
     * Description    
     * @param {type} aTracefunc Description    
     */
    function insertTraceKit(aTracefunc) {

      TraceKit.report.subscribe(aTracefunc);

      function wrapped(aThis) {
        var w = (aThis.target || aThis);

        function docUnloadChange(e) {
          TraceKit.report.unsubscribe(yourLogger, e.currentTarget);
          //console.log('unload', e.currentTarget.location.href, e.currentTarget.readyState);
          var l = e.currentTarget.location.href;
          var checkForUnload = function (e) {
            try {
              if (l != e.location.href) {
                clearInterval(unloadCheckInterval);
                //console.log(e.location.href);
                TraceKit.report.subscribe(aTracefunc, e);
              }
            } catch (exception) {
              clearInterval(unloadCheckInterval);
              unloadCheckInterval = setInterval(checkForUnload, 100, this);
              //console.log('cross-origin frame detected');
            }
          };
          var unloadCheckInterval = setInterval(checkForUnload, 1, this);

        }

        TraceKit.report.subscribe(aTracefunc, w.contentWindow);
        try {
          w.contentWindow.addEventListener("unload", docUnloadChange);
        } catch (e) {
          //console.log('cross-origin frame detected');
        }
      }

      var frames = document.querySelectorAll('frame,iframe');
      for (var i = 0; i < frames.length; i++) {
        frames[i].onload = wrapped;
        try {
          // console.log(frames[i].contentDocument.readyState, frames[i].contentDocument.location.href);
          frames[i].readyStateCheckInterval = setInterval(fasteractiveTrace, 1, frames[i]);
        } catch (e) {
          //console.log('cross-origin frame detected');
        }
      }

      function fasteractiveTrace(e) {
        try {
          if (e.contentDocument) {
            if (e.contentDocument.readyState == "complete" || e.contentDocument.readyState == "interactive") {
              wrapped(e);
              clearInterval(e.readyStateCheckInterval);
            }
            // console.log(e.contentDocument.readyState, e.contentDocument.location.href);
          }
        } catch (exception) {
          //console.log('cross-origin frame detected');
        }
      }

    }

    var readyStateCheckInterval = setInterval(waitInit, 10, this);

    function waitInit() {
      //console.log(document.readyState);
      if (document.readyState === "complete" || document.readyState === "interactive") {
        clearInterval(readyStateCheckInterval);
        insertTraceKit(yourLogger);
      }
    }

aquadk avatar Jul 03 '17 07:07 aquadk

Thanks, were any other changes required for this pr? Do you think we should put this in a wiki entry?

niemyjski avatar Jul 03 '17 13:07 niemyjski

Thanks, were any other changes required for this pr? Do you think we should put this in a wiki entry?

niemyjski avatar Feb 23 '18 17:02 niemyjski

Thanks, were any other changes required for this pr? Do you think we should put this in a wiki entry? I'd like to get this merged in and cleaned up

niemyjski avatar Jul 09 '18 19:07 niemyjski

I have merged our code and committed all changes.

aquadk avatar Jul 17 '18 12:07 aquadk

Forgot to push all changes.. sorry

aquadk avatar Jul 18 '18 12:07 aquadk

Hello, I'm not seeing any of the latest changes, can you please review the files changed here as you can see we added more code around installing additional global handlers.

niemyjski avatar Jul 30 '18 14:07 niemyjski

All code are pushed into aquadk/Tracekit master branch. Including global handlers.

aquadk avatar Aug 15 '18 07:08 aquadk

Looks good, I added two comments on things, if we feel we are good I'll merge it in.

niemyjski avatar Aug 18 '18 13:08 niemyjski

@aquadk Could you please review the feedback so we can take your great work and get it merged in.

niemyjski avatar Sep 07 '18 13:09 niemyjski

Can we get this updated so we can get it merged in.

niemyjski avatar Nov 20 '18 19:11 niemyjski

Can we get this updated so we can get it merged in.

niemyjski avatar Apr 08 '20 13:04 niemyjski

Can we get this updated so we can get it merged in.

niemyjski avatar Sep 19 '24 14:09 niemyjski