TraceKit
TraceKit copied to clipboard
TraceKit can now be used on frames
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();
}
}
Hi, Have now made the changes you asked for.
I'm sorry for taking so long to get back to this. What is the current status of this?
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);
}
}
Thanks, were any other changes required for this pr? Do you think we should put this in a wiki entry?
Thanks, were any other changes required for this pr? Do you think we should put this in a wiki entry?
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
I have merged our code and committed all changes.
Forgot to push all changes.. sorry
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.
All code are pushed into aquadk/Tracekit master branch. Including global handlers.
Looks good, I added two comments on things, if we feel we are good I'll merge it in.
@aquadk Could you please review the feedback so we can take your great work and get it merged in.
Can we get this updated so we can get it merged in.
Can we get this updated so we can get it merged in.
Can we get this updated so we can get it merged in.