Conversation
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();
}
}
niemyjski
left a comment
There was a problem hiding this comment.
Thanks for the pr, There are some things I saw that need to be updated or clarified,
I'm really hesitant on accepting this. I do see the value in this, but want to know the exact benefits gained. Also, we haven't really had any users report not seeing errors in iframes. I'd like to move away from window specific code, and have this in a plugin ideally. Can you add some tests for all the code here specifically one that deals with frames.
tracekit.js
Outdated
| installGlobalHandler(); | ||
| handlers.push(handler); | ||
| function subscribe(handler, aWindow) { | ||
| aWindow = (aWindow || window); |
There was a problem hiding this comment.
Can we rename aWindow to win it's shorter and you know what it does, it's also consistent with your function above.
tracekit.js
Outdated
| } | ||
| } else if ((parts = lineRE3.exec(lines[line]))) { | ||
| var url = window.location.href.replace(/#.*$/, ''); | ||
| var url = TraceKit.windowPointer.location.href.replace(/#.*$/, ''); |
There was a problem hiding this comment.
What about parsing source in the inner frame?
tracekit.js
Outdated
| lineRE3 = /^\s*Line (\d+) of function script\s*$/i, | ||
| stack = [], | ||
| scripts = (window && window.document && window.document.getElementsByTagName('script')), | ||
| scripts = (TraceKit.windowPointer && TraceKit.windowPointer.document && TraceKit.windowPointer.document.getElementsByTagName('script')), |
There was a problem hiding this comment.
Can you move this window pointer to a local variable, this will not minify very well.
tracekit.js
Outdated
| var domain = ''; | ||
| try { domain = window.document.domain; } catch (e) { } | ||
| try { | ||
| domain = window.document.domain; |
There was a problem hiding this comment.
Why not use the pointer here>
tracekit.js
Outdated
| _oldOnerrorHandler = window.onerror; | ||
| window.onerror = traceKitWindowOnError; | ||
| _onErrorHandlerInstalled = true; | ||
| var _oldOnerrorHandler = aWindow.onerror; |
There was a problem hiding this comment.
if this is no longer a private field we need to change the variable name
| notifyHandlers(stack, true, arguments); | ||
| } | ||
|
|
||
| if (_oldOnerrorHandler) { |
There was a problem hiding this comment.
Any reason for removing this?
tracekit.js
Outdated
| if (_has(handlers, i) && handlers[i][1] === TraceKit.windowPointer) { | ||
| try { | ||
| handlers[i](stack, isWindowError, error); | ||
| handlers[i][0](stack, isWindowError, (aArguments.length > 4) ? aArguments[4] : null); |
There was a problem hiding this comment.
What's the 3rd and 4th parameter here? This became much less readable.
tracekit.js
Outdated
| } catch (inner) { | ||
| exception = inner; | ||
| } | ||
| if (handlers[i][1]._oldOnerrorHandler) { |
There was a problem hiding this comment.
I thought this was a local variable.
Changed aWindow til win
+ made code easier to read
|
Hi, |
tracekit.js
Outdated
| * @throws An exception if an error occurs while calling an handler. | ||
| */ | ||
| function notifyHandlers(stack, isWindowError, error) { | ||
| function notifyHandlers(stack, isWindowError, aArguments) { |
There was a problem hiding this comment.
What does arguments contain? Can we call this args? and maybe a comment to break down what the possible structure is.
There was a problem hiding this comment.
ok, arguments contains all the arguments from onerror event
tracekit.js
Outdated
| try { | ||
| handlers[i](stack, isWindowError, error); | ||
| var errorObj=(aArguments.length > 4) ? aArguments[4] : null; | ||
| handlers[i][0](stack, isWindowError, errorObj); |
There was a problem hiding this comment.
This is kind of confusing, so we call a method with stack, isWindowErorr and an array with 4 items? We seem to only be using the error object, so it might be better to revert this signature to just be error object. Previous thought: Maybe we need to add a comment stating that these arguments are actually: message, url, lineNo, columnNo, errorObj (if we were on es6, restructuring would make this so much more readable but we can't use that :(`,
tracekit.js
Outdated
| exception = inner; | ||
| } | ||
| // Call old onerror events | ||
| if (handlers[i][2]) { |
There was a problem hiding this comment.
We weren't doing this before were we? It's just really hard to follow this and make sense of what's going on.. We call all the other handlers in a try catch.
tracekit.js
Outdated
| function traceKitWindowOnError(message, url, lineNo, columnNo, errorObj) { | ||
| var stack = null; | ||
|
|
||
| TraceKit.windowPointer = this; |
There was a problem hiding this comment.
So this modifies the pointer which might of been set earlier when you subscribed. I'm not sure this should be updated as it would change the subscription handler? Thoughts?
tracekit.js
Outdated
| if (isWindowAccessible(win)) { | ||
| for (var i = handlers.length - 1; i >= 0; --i) { | ||
| if (handlers[i] === handler) { | ||
| if (handlers[i][0] === handler && win === handlers[i][1]) { |
There was a problem hiding this comment.
What's all stored on handler now in this array?
There was a problem hiding this comment.
We weren't doing this before, but since you are calling unsubscribe and you have an array with the previous error handler. Do you think we should be setting it back?
There was a problem hiding this comment.
Good point, i will insert the code
| var debug = false, | ||
| sourceCache = {}; | ||
| sourceCache = {}, | ||
| curWin = TraceKit.windowPointer; |
There was a problem hiding this comment.
Can we rename this to win
| * @memberof TraceKit.computeStackTrace | ||
| */ | ||
| function computeStackTrace(ex, depth) { | ||
| curWin = TraceKit.windowPointer; |
There was a problem hiding this comment.
This doesn't seem to be used
tracekit.js
Outdated
| var originalFn = window[fnName]; | ||
| window[fnName] = function traceKitAsyncExtension() { | ||
| var originalFn = TraceKit.windowPointer[fnName]; | ||
| TraceKit.windowPointer[fnName] = function traceKitAsyncExtension() { |
There was a problem hiding this comment.
Might want to store this in a variable
|
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. |
|
Thanks, were any other changes required for this pr? Do you think we should put this in a wiki entry? |
1 similar comment
|
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 |
| if (lastException === ex) { | ||
| window.setTimeout(function () { | ||
| if (lastException == ex) { | ||
| processLastException(); |
There was a problem hiding this comment.
Any specific reason to putting this to window? It might block users from using this in node?
tracekit.js
Outdated
| }; | ||
|
|
||
| notifyHandlers(stack, true, arguments); | ||
| notifyHandlers(stack, true, null); |
There was a problem hiding this comment.
any reason for not passing through the arguments?
tracekit.js
Outdated
| @@ -204,17 +215,16 @@ TraceKit.report = (function reportModuleWrapper() { | |||
| TraceKit.windowPointer = this; | |||
There was a problem hiding this comment.
any reason for not passing through the arguments?
New handler object, which include Onunhandledrejection too.
package version upgraded
|
I have merged our code and committed all changes. |
niemyjski
left a comment
There was a problem hiding this comment.
I noticed that you merged in the lastest master changes but rejected all of those. Can you please go back over this pr and make sure we aren't missing anything like
-
installGlobalHandler(); -
installGlobalUnhandledRejectionHandler(); That would be greatly appreciated
# Conflicts: # tracekit.js
|
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. |
| } | ||
|
|
||
| if (_oldOnerrorHandler) { | ||
| return _oldOnerrorHandler.apply(this, arguments); |
There was a problem hiding this comment.
I think we were calling old handlers to preserve existing work flows.
| { | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "target": "es6", |
There was a problem hiding this comment.
We actually have to target es3 everywhere :.
|
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. |
| declare global { | ||
| interface Window { | ||
| onunhandledrejection: PromiseRejectionEvent; | ||
| _onErrorHandlerInstalled : boolean; |
There was a problem hiding this comment.
Do we really need to expose this private var?
|
Can we get this updated so we can get it merged in. |
2 similar comments
|
Can we get this updated so we can get it merged in. |
|
Can we get this updated so we can get it merged in. |
|
There are a lot of merge conflicts and I'd really like to get this merged in, would it be possible to resolve the conflicts. Really sorry it's taken so long. |
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.