From 9bf87094d23285525c10f15495f123996163d1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Tue, 17 Jan 2017 01:24:31 +0100 Subject: [PATCH 01/13] 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(); } } --- tracekit.js | 72 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/tracekit.js b/tracekit.js index 2b013e6..2971fc4 100644 --- a/tracekit.js +++ b/tracekit.js @@ -118,14 +118,22 @@ TraceKit.report = (function reportModuleWrapper() { lastException = null, lastExceptionStack = null; + function isWindowAccessible(win) { + try { + return (win.location.host); + } catch (e) {} + } /** * Add a crash handler. * @param {Function} handler * @memberof TraceKit.report */ - function subscribe(handler) { - installGlobalHandler(); - handlers.push(handler); + function subscribe(handler, aWindow) { + aWindow = (aWindow || window); + if (isWindowAccessible(aWindow)) { + TraceKit.windowPointer = aWindow; + installGlobalHandler(handler, aWindow); + } } /** @@ -133,12 +141,15 @@ TraceKit.report = (function reportModuleWrapper() { * @param {Function} handler * @memberof TraceKit.report */ - function unsubscribe(handler) { + function unsubscribe(handler, aWindow) { + aWindow = (aWindow || window); + if (isWindowAccessible(aWindow)) { for (var i = handlers.length - 1; i >= 0; --i) { - if (handlers[i] === handler) { + if (handlers[i][0] === handler && aWindow === handlers[i][1]) { handlers.splice(i, 1); } } + } } /** @@ -149,27 +160,29 @@ TraceKit.report = (function reportModuleWrapper() { * @memberof TraceKit.report * @throws An exception if an error occurs while calling an handler. */ - function notifyHandlers(stack, isWindowError, error) { + function notifyHandlers(stack, isWindowError, aArguments) { var exception = null; if (isWindowError && !TraceKit.collectWindowErrors) { return; } for (var i in handlers) { - if (_has(handlers, i)) { + 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); } catch (inner) { exception = inner; } + if (handlers[i][1]._oldOnerrorHandler) { + return handlers[i][1]._oldOnerrorHandler.apply(handlers[i][1], aArguments); } } + } if (exception) { throw exception; } } - var _oldOnerrorHandler, _onErrorHandlerInstalled; /** * Ensures all global unhandled exceptions are recorded. @@ -183,13 +196,13 @@ TraceKit.report = (function reportModuleWrapper() { */ function traceKitWindowOnError(message, url, lineNo, columnNo, errorObj) { var stack = null; - + TraceKit.windowPointer = this; if (lastExceptionStack) { TraceKit.computeStackTrace.augmentStackTraceWithInitialElement(lastExceptionStack, url, lineNo, message); - processLastException(); + processLastException(arguments); } else if (errorObj) { stack = TraceKit.computeStackTrace(errorObj); - notifyHandlers(stack, true, errorObj); + notifyHandlers(stack, true, arguments); } else { var location = { 'url': url, @@ -204,12 +217,10 @@ TraceKit.report = (function reportModuleWrapper() { 'stack': [location] }; - notifyHandlers(stack, true, null); + notifyHandlers(stack, true, arguments); } - if (_oldOnerrorHandler) { - return _oldOnerrorHandler.apply(this, arguments); - } + return false; } @@ -218,13 +229,14 @@ TraceKit.report = (function reportModuleWrapper() { * Install a global onerror handler * @memberof TraceKit.report */ - function installGlobalHandler () { - if (_onErrorHandlerInstalled === true) { + function installGlobalHandler(aHandlers, aWindow) { + if (aWindow._onErrorHandlerInstalled === true) { return; } - _oldOnerrorHandler = window.onerror; - window.onerror = traceKitWindowOnError; - _onErrorHandlerInstalled = true; + var _oldOnerrorHandler = aWindow.onerror; + aWindow.onerror = traceKitWindowOnError; + aWindow._onErrorHandlerInstalled = true; + handlers.push([aHandlers, aWindow, _oldOnerrorHandler]); } /** @@ -419,7 +431,9 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { */ var source = ''; var domain = ''; - try { domain = window.document.domain; } catch (e) { } + try { + domain = window.document.domain; + } catch (e) {} var match = /(.*)\:\/\/([^:\/]+)([:\d]*)\/{0,1}([\s\S]*)/.exec(url); if (match && match[2] === domain) { source = loadSource(url); @@ -590,12 +604,12 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { * @memberof TraceKit.computeStackTrace */ function findSourceByFunctionBody(func) { - if (_isUndefined(window && window.document)) { + if (_isUndefined(TraceKit.windowPointer && window.document)) { return; } - var urls = [window.location.href], - scripts = window.document.getElementsByTagName('script'), + var urls = [TraceKit.windowPointer.location.href], + scripts = TraceKit.windowPointer.document.getElementsByTagName('script'), body, code = '' + func, codeRE = /^function(?:\s+([\w$]+))?\s*\(([\w\s,]*)\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/, @@ -880,7 +894,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { lineRE2 = /^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i, 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')), inlineScriptBlocks = [], parts; @@ -921,7 +935,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { } } } else if ((parts = lineRE3.exec(lines[line]))) { - var url = window.location.href.replace(/#.*$/, ''); + var url = TraceKit.windowPointer.location.href.replace(/#.*$/, ''); var re = new RegExp(escapeCodeAsRegExpForMatchingInsideHTML(lines[line + 1])); var src = findSourceInUrls(re, [url]); item = { @@ -1195,8 +1209,8 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { */ TraceKit.extendToAsynchronousCallbacks = function () { var _helper = function _helper(fnName) { - var originalFn = window[fnName]; - window[fnName] = function traceKitAsyncExtension() { + var originalFn = TraceKit.windowPointer[fnName]; + TraceKit.windowPointer[fnName] = function traceKitAsyncExtension() { // Make a copy of the arguments var args = _slice.call(arguments); var originalCallback = args[0]; From 1ba9d8551eb30b189d5daec1a11bac76e9666fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Wed, 18 Jan 2017 11:04:46 +0100 Subject: [PATCH 02/13] rename param Changed aWindow til win --- tracekit.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tracekit.js b/tracekit.js index 2971fc4..57f2b32 100644 --- a/tracekit.js +++ b/tracekit.js @@ -128,11 +128,11 @@ TraceKit.report = (function reportModuleWrapper() { * @param {Function} handler * @memberof TraceKit.report */ - function subscribe(handler, aWindow) { - aWindow = (aWindow || window); - if (isWindowAccessible(aWindow)) { - TraceKit.windowPointer = aWindow; - installGlobalHandler(handler, aWindow); + function subscribe(handler, win) { + win = (win || window); + if (isWindowAccessible(win)) { + TraceKit.windowPointer = win; + installGlobalHandler(handler, win); } } @@ -141,11 +141,11 @@ TraceKit.report = (function reportModuleWrapper() { * @param {Function} handler * @memberof TraceKit.report */ - function unsubscribe(handler, aWindow) { - aWindow = (aWindow || window); - if (isWindowAccessible(aWindow)) { + function unsubscribe(handler, win) { + win = (win || window); + if (isWindowAccessible(win)) { for (var i = handlers.length - 1; i >= 0; --i) { - if (handlers[i][0] === handler && aWindow === handlers[i][1]) { + if (handlers[i][0] === handler && win === handlers[i][1]) { handlers.splice(i, 1); } } From a182223874558885a2a779e73d81cd5e0365d95a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Wed, 18 Jan 2017 11:08:50 +0100 Subject: [PATCH 03/13] removed _ value is not private anymore --- tracekit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracekit.js b/tracekit.js index 57f2b32..e0879f9 100644 --- a/tracekit.js +++ b/tracekit.js @@ -233,10 +233,10 @@ TraceKit.report = (function reportModuleWrapper() { if (aWindow._onErrorHandlerInstalled === true) { return; } - var _oldOnerrorHandler = aWindow.onerror; + var oldOnerrorHandler = aWindow.onerror; aWindow.onerror = traceKitWindowOnError; aWindow._onErrorHandlerInstalled = true; - handlers.push([aHandlers, aWindow, _oldOnerrorHandler]); + handlers.push([aHandlers, aWindow, oldOnerrorHandler]); } /** From 93a7322e4d7ff2ea8d0d612da3be2e757ecdd4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Wed, 18 Jan 2017 15:21:25 +0100 Subject: [PATCH 04/13] Added local value for window pointer + made code easier to read --- tracekit.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tracekit.js b/tracekit.js index e0879f9..00b6354 100644 --- a/tracekit.js +++ b/tracekit.js @@ -168,12 +168,14 @@ TraceKit.report = (function reportModuleWrapper() { for (var i in handlers) { if (_has(handlers, i) && handlers[i][1] === TraceKit.windowPointer) { try { - handlers[i][0](stack, isWindowError, (aArguments.length > 4) ? aArguments[4] : null); + var errorObj=(aArguments.length > 4) ? aArguments[4] : null; + handlers[i][0](stack, isWindowError, errorObj); } catch (inner) { exception = inner; } - if (handlers[i][1]._oldOnerrorHandler) { - return handlers[i][1]._oldOnerrorHandler.apply(handlers[i][1], aArguments); + // Call old onerror events + if (handlers[i][2]) { + return handlers[i][2].apply(handlers[i][1], aArguments); } } } @@ -373,9 +375,10 @@ TraceKit.report = (function reportModuleWrapper() { * @memberof TraceKit * @namespace */ -TraceKit.computeStackTrace = (function computeStackTraceWrapper() { +TraceKit.computeStackTrace = (function() { var debug = false, - sourceCache = {}; + sourceCache = {}, + curWin = TraceKit.windowPointer; /** * Attempts to retrieve source code via XMLHttpRequest, which is used @@ -432,7 +435,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { var source = ''; var domain = ''; try { - domain = window.document.domain; + domain = curWin.document.domain; } catch (e) {} var match = /(.*)\:\/\/([^:\/]+)([:\d]*)\/{0,1}([\s\S]*)/.exec(url); if (match && match[2] === domain) { @@ -604,12 +607,12 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { * @memberof TraceKit.computeStackTrace */ function findSourceByFunctionBody(func) { - if (_isUndefined(TraceKit.windowPointer && window.document)) { + if (_isUndefined(curWin && curWin.document)) { return; } - var urls = [TraceKit.windowPointer.location.href], - scripts = TraceKit.windowPointer.document.getElementsByTagName('script'), + var urls = [curWin.location.href], + scripts = curWin.document.getElementsByTagName('script'), body, code = '' + func, codeRE = /^function(?:\s+([\w$]+))?\s*\(([\w\s,]*)\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/, @@ -894,7 +897,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { lineRE2 = /^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i, lineRE3 = /^\s*Line (\d+) of function script\s*$/i, stack = [], - scripts = (TraceKit.windowPointer && TraceKit.windowPointer.document && TraceKit.windowPointer.document.getElementsByTagName('script')), + scripts = (curWin && curWin.document && curWin.document.getElementsByTagName('script')), inlineScriptBlocks = [], parts; @@ -935,7 +938,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { } } } else if ((parts = lineRE3.exec(lines[line]))) { - var url = TraceKit.windowPointer.location.href.replace(/#.*$/, ''); + var url = curWin.location.href.replace(/#.*$/, ''); var re = new RegExp(escapeCodeAsRegExpForMatchingInsideHTML(lines[line + 1])); var src = findSourceInUrls(re, [url]); item = { @@ -1123,6 +1126,7 @@ TraceKit.computeStackTrace = (function computeStackTraceWrapper() { * @memberof TraceKit.computeStackTrace */ function computeStackTrace(ex, depth) { + curWin = TraceKit.windowPointer; var stack = null; depth = (depth == null ? 0 : +depth); From 69b165e5e9ee9b76fff68303b770d9c0dca1a32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Wed, 18 Jan 2017 15:33:49 +0100 Subject: [PATCH 05/13] Set theme jekyll-theme-tactile --- _config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 _config.yml diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..259a24e --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-tactile \ No newline at end of file From 343dc39c171bee6a425f9d3e4010bcf032bc1dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Wed, 18 Jan 2017 20:12:56 +0100 Subject: [PATCH 06/13] Doc and better names on function arguments --- tracekit.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tracekit.js b/tracekit.js index 00b6354..36e482f 100644 --- a/tracekit.js +++ b/tracekit.js @@ -126,6 +126,7 @@ TraceKit.report = (function reportModuleWrapper() { /** * Add a crash handler. * @param {Function} handler + * @param {window} win default is current window. Need if you want to subcribe tracekit to another window/frame * @memberof TraceKit.report */ function subscribe(handler, win) { @@ -139,6 +140,7 @@ TraceKit.report = (function reportModuleWrapper() { /** * Remove a crash handler. * @param {Function} handler + * @param {window} win default is current window. Need if you want to unsubcribe tracekit to another window/frame * @memberof TraceKit.report */ function unsubscribe(handler, win) { @@ -146,6 +148,9 @@ TraceKit.report = (function reportModuleWrapper() { if (isWindowAccessible(win)) { for (var i = handlers.length - 1; i >= 0; --i) { if (handlers[i][0] === handler && win === handlers[i][1]) { + // put back the old event handler + win.onerror = handlers[i][2]; + // remove handler from handlers handlers.splice(i, 1); } } @@ -156,11 +161,11 @@ TraceKit.report = (function reportModuleWrapper() { * Dispatch stack information to all handlers. * @param {TraceKit.StackTrace} stack * @param {boolean} isWindowError Is this a top-level window error? - * @param {Error=} error The error that's being handled (if available, null otherwise) + * @param {array} args all the arguments from onerror event. Array of [Message, url, lineNo, columnNo, errorObj] * @memberof TraceKit.report * @throws An exception if an error occurs while calling an handler. */ - function notifyHandlers(stack, isWindowError, aArguments) { + function notifyHandlers(stack, isWindowError, args) { var exception = null; if (isWindowError && !TraceKit.collectWindowErrors) { return; @@ -168,14 +173,14 @@ TraceKit.report = (function reportModuleWrapper() { for (var i in handlers) { if (_has(handlers, i) && handlers[i][1] === TraceKit.windowPointer) { try { - var errorObj=(aArguments.length > 4) ? aArguments[4] : null; + var errorObj=(args.length > 4) ? args[4] : null; handlers[i][0](stack, isWindowError, errorObj); } catch (inner) { exception = inner; } // Call old onerror events if (handlers[i][2]) { - return handlers[i][2].apply(handlers[i][1], aArguments); + return handlers[i][2].apply(handlers[i][1], args); } } } @@ -229,16 +234,18 @@ TraceKit.report = (function reportModuleWrapper() { /** * Install a global onerror handler + * @param {Function} handler + * @param {window} win tracekit will be attached to this window * @memberof TraceKit.report */ - function installGlobalHandler(aHandlers, aWindow) { - if (aWindow._onErrorHandlerInstalled === true) { + function installGlobalHandler(handler, win) { + if (win._onErrorHandlerInstalled === true) { return; } - var oldOnerrorHandler = aWindow.onerror; - aWindow.onerror = traceKitWindowOnError; - aWindow._onErrorHandlerInstalled = true; - handlers.push([aHandlers, aWindow, oldOnerrorHandler]); + var oldOnerrorHandler = win.onerror; + win.onerror = traceKitWindowOnError; + win._onErrorHandlerInstalled = true; + handlers.push([handlers, win, oldOnerrorHandler]); } /** From 064527291499a61ce274d913f7498e91393ca35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Wed, 18 Jan 2017 20:31:59 +0100 Subject: [PATCH 07/13] Doc and return value --- tracekit.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tracekit.js b/tracekit.js index 36e482f..4548fbe 100644 --- a/tracekit.js +++ b/tracekit.js @@ -118,10 +118,17 @@ TraceKit.report = (function reportModuleWrapper() { lastException = null, lastExceptionStack = null; + + /** + * Can the window be used + * @param {type} win + * @returns {boolean} + * @memberof TraceKit.report + */ function isWindowAccessible(win) { try { return (win.location.host); - } catch (e) {} + } catch (e) { return false; } } /** * Add a crash handler. From 9b0c75d9c61f85cca11d066d4c20832a2876f45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Tue, 17 Jul 2018 13:56:43 +0200 Subject: [PATCH 08/13] Changed fra grunt to gulp package version upgraded --- Gruntfile.js | 66 ----------------------------------------------- Gulpfile.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 29 +++++++++++---------- 3 files changed, 89 insertions(+), 79 deletions(-) delete mode 100644 Gruntfile.js create mode 100644 Gulpfile.js diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index b4f944b..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,66 +0,0 @@ -/*global module:false*/ -module.exports = function (grunt) { - 'use strict'; - - /** - * Bypass grunt-bump limitation - * see https://github.com/vojtajina/grunt-bump/pull/189 - */ - var gruntBumpPrereleaseName = 'rc'; - grunt.initConfig({ - bump: { - options: { - files: ['package.json', 'bower.json', 'appveyor.yml'], - prereleaseName: gruntBumpPrereleaseName, - /** - * Need to create a new RegExp for appveyor - * https://github.com/vojtajina/grunt-bump/issues/190 - */ - regExp: new RegExp( - '([\'|\"]?version[\'|\"]?[ ]*:[ ]*[\'|\"]?)(\\d+\\.\\d+\\.\\d+(-' + - gruntBumpPrereleaseName + - '\\.\\d+)?(-\\d+)?)[\\d||A-a|-]*([\'|\"]?)', 'i' - ) - } - }, - jshint: { - options: { - jshintrc: '.jshintrc' - }, - lint: { - src: [ - 'grunt.js', - 'tracekit.js' - ] - } - }, - jasmine : { - src: [ - 'tracekit.js', - 'spec/fixtures/captured-errors.js' - ], - options: { - specs: 'spec/*-spec.js' - } - }, - jsdoc : { - dist: { - src: ['tracekit.js'], - options: { - destination: 'doc', - readme: 'README.md', - configure: 'jsdoc.conf.json' - } - } - } - }); - - grunt.loadNpmTasks('grunt-contrib-jasmine'); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-bump'); - grunt.loadNpmTasks('grunt-jsdoc'); - - grunt.registerTask('doc', ['jsdoc']); - grunt.registerTask('test', ['jasmine']); - grunt.registerTask('default', ['jshint:lint']); -}; diff --git a/Gulpfile.js b/Gulpfile.js new file mode 100644 index 0000000..80c4030 --- /dev/null +++ b/Gulpfile.js @@ -0,0 +1,73 @@ +/* jshint esversion: 6 */ +/* jshint node: true */ +const gulp = require('gulp'); +const Server = require('karma').Server; +const jshint = require('gulp-jshint'); +const bump = require('gulp-bump'); + +const srcCode = ['./tracekit.js']; +/** + * Run test once and exit + */ +gulp.task('test', function (done) { + new Server({ + configFile: __dirname + '/karma.conf.js', + singleRun: true + }, done).start(); +}); + +/** + * Watch for file changes and re-run tests on each change + */ +gulp.task('tdd', function (done) { + new Server({ + configFile: __dirname + '/karma.conf.js' + }, done).start(); +}); + +/** + * Watch for file changes and re-run tests on each change + */ +gulp.task('tddchrome', function (done) { + new Server({ + configFile: __dirname + '/karma.conf.chrome.js' + }, done).start(); +}); + +// We do this over using include/exclude to make everything feel gulp-like! +gulp.task('doc', function (cb) { + let jsdoc = require('gulp-jsdoc3'); + + let config = require('./jsdoc.conf.json'); + gulp.src(['README.md'].concat(srcCode), { + read: false + }) + .pipe(jsdoc(config, cb)); +}); + + +gulp.task('lint', function () { + return gulp.src(['./tracekit.js', './Gulpfile.js']) + .pipe(jshint()) + .pipe(jshint.reporter('default')); +}); + + +// Update bower, component, npm at once: +gulp.task('bump', function () { + gulp.src(['package.json', 'bower.json', 'appveyor.yml']) + .pipe(bump({ + type: 'patch' + })) + .pipe(gulp.dest('./')); +}); + + +// Update bower, component, npm at once: +gulp.task('bump-minor', function () { + gulp.src(['package.json', 'bower.json', 'appveyor.yml']) + .pipe(bump({ + type: 'minor' + })) + .pipe(gulp.dest('./')); +}); diff --git a/package.json b/package.json index 1f3218c..23c30fe 100644 --- a/package.json +++ b/package.json @@ -17,22 +17,25 @@ ], "license": "MIT", "devDependencies": { - "grunt": "1.0.1", - "grunt-bump": "^0.8.0", - "grunt-cli": "1.2.0", - "grunt-contrib-jasmine": "1.1.0", - "grunt-contrib-jshint": "1.1.0", - "grunt-jsdoc": "2.1.0", - "jasmine": "2.6.0", - "jasmine-core": "2.6.4", - "karma": "1.7.0", - "karma-jasmine": "1.1.0", + "gulp": "3.9.1", + "gulp-jsdoc3": "^2.0.0", + "gulp-jshint": "^2.1.0", + "jasmine": "3.1.0", + "jasmine-core": "3.1.0", + "jsdoc": "3.5.5", + "jshint": "^2.9.5", + "karma": "2.0.4", + "karma-chrome-launcher": "2.2.0", + "karma-jasmine": "1.1.2", "karma-phantomjs-launcher": "1.0.4", - "phantomjs-prebuilt": "2.1.14" + "phantomjs-prebuilt": "2.1.16" }, "scripts": { - "test": "grunt test" + "test": "gulp test" }, "typings": "tracekit.d.ts", - "author": "Blake Niemyjski " + "author": "Blake Niemyjski ", + "dependencies": { + "gulp-bump": "^3.1.1" + } } From 66aa36c33aec4361ba27e62ce88c62213768aa70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Tue, 17 Jul 2018 13:58:36 +0200 Subject: [PATCH 09/13] Updated karma/ jasmine with chrome for debugging --- .vscode/launch.json | 31 ++++++++++++++++ karma.conf.chrome.js | 75 +++++++++++++++++++++++++++++++++++++++ karma.conf.js | 2 +- spec/support/jasmine.json | 10 ++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 karma.conf.chrome.js create mode 100644 spec/support/jasmine.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..8fbe3ac --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,31 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "attach", + "name": "Attach Karma Chrome", + "address": "localhost", + "port": 9333, + "pathMapping": { + "/": "${workspaceRoot}/", + "/base/": "${workspaceRoot}/" + }, + "webRoot": "${workspaceRoot}/" + }, + { + "type": "chrome", + "request": "launch", + "name": "Test", + "sourceMaps": true, + "webRoot": "${workspaceRoot}/", + "url": "http://localhost:9333/debug.html", + "runtimeArgs": [ + "--headless" + ] + } + ] +} \ No newline at end of file diff --git a/karma.conf.chrome.js b/karma.conf.chrome.js new file mode 100644 index 0000000..24cf545 --- /dev/null +++ b/karma.conf.chrome.js @@ -0,0 +1,75 @@ +// Karma configuration + +module.exports = function(config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + plugins: [ + 'karma-phantomjs-launcher', + 'karma-jasmine', + 'karma-chrome-launcher' + ], + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], + + + // list of files / patterns to load in the browser + files: [ + 'tracekit.js', + 'spec/**/*.js' + ], + + + // list of files to exclude + exclude: [ + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + + // web server port + port: 9333, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['ChromeDebugging'], + + customLaunchers: { + ChromeDebugging: { + base: 'Chrome', + flags: ['--remote-debugging-prt=9333'], + debug: true + } + }, + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false + }) +}; diff --git a/karma.conf.js b/karma.conf.js index f2d3835..b5fd4fc 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -37,7 +37,7 @@ module.exports = function(config) { // web server port - port: 9876, + port: 9333, // enable / disable colors in the output (reporters and logs) diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json new file mode 100644 index 0000000..11ae489 --- /dev/null +++ b/spec/support/jasmine.json @@ -0,0 +1,10 @@ +{ + "spec_dir": "spec", + "spec_files": [ + "*[sS]pec.js" + ], + "helpers": [ + "../spec/fixtures/captured-errors.js", + "../tracekit.js" + ] +} \ No newline at end of file From c17ff2722b1e8394a9c93c1e238c37391bd1141e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Tue, 17 Jul 2018 13:59:09 +0200 Subject: [PATCH 10/13] jsdoc output to doc folder --- jsdoc.conf.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 82cec7e..b79edc5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,5 +5,9 @@ }, "plugins": [ "plugins/markdown" - ] + ], + "opts": { + "destination": "./doc/", + "recurse": true + } } From c4f0d94e3f7f94fe0d7d82e3c07bb1a7689668dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Tue, 17 Jul 2018 13:59:43 +0200 Subject: [PATCH 11/13] VS code config for typescript --- tsconfig.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..90ee79e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "lib": ["es5", "es6", "dom"], + "allowJs": true, + "checkJs": true + }, + "exclude": [ + "node_modules" + ] +} \ No newline at end of file From ca67a8f5db61dacfacad8866a474b897d049a99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Tue, 17 Jul 2018 14:00:28 +0200 Subject: [PATCH 12/13] Only use oldhandler if there is one. --- spec/tracekit-spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/tracekit-spec.js b/spec/tracekit-spec.js index 666d816..1a6d194 100644 --- a/spec/tracekit-spec.js +++ b/spec/tracekit-spec.js @@ -129,7 +129,9 @@ if (message === testMessage || lineNo === testLineNo) { return true; } - return oldOnErrorHandler.apply(this, arguments); + if (oldOnErrorHandler) { + return oldOnErrorHandler.apply(this, arguments); + } }; }); From 6864a38fca7785f18a9a65663acae157aee8a636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Lykke=20Dahl?= Date: Fri, 20 Jul 2018 10:19:43 +0200 Subject: [PATCH 13/13] Added code to doc, about Iframe --- tutorials/Iframes.html | 82 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tutorials/Iframes.html diff --git a/tutorials/Iframes.html b/tutorials/Iframes.html new file mode 100644 index 0000000..63e750c --- /dev/null +++ b/tutorials/Iframes.html @@ -0,0 +1,82 @@ +

IFrame solution

+ +

This should be used for iframe pages. Only include this code and it will inject javascript into any frames.

+ +
+/**    
+* 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);
+ }
+}
+
\ No newline at end of file