From 603d5da85520d64ed76e54de2d43ec59774ef85f Mon Sep 17 00:00:00 2001 From: Nigel Heron Date: Thu, 4 Jan 2018 15:26:30 -0500 Subject: [PATCH] Work around minification that breaks in IE8 and quirks mode --- boomerang.js | 5 +- plugins/compression.js | 10 +- .../boomerangDelayedSnippetNoScript.tpl | 38 +------- .../boomerangSnippetMin.tpl | 3 + .../boomerangSnippetMinNoScript.tpl | 3 + .../boomerangSnippetNoScript.tpl | 12 ++- .../00-basic/13-onload-minified.html | 12 +++ .../00-basic/13-onload-minified.js | 95 +++++++++++++++++++ 8 files changed, 133 insertions(+), 45 deletions(-) create mode 100644 tests/page-template-snippets/boomerangSnippetMin.tpl create mode 100644 tests/page-template-snippets/boomerangSnippetMinNoScript.tpl create mode 100644 tests/page-templates/00-basic/13-onload-minified.html create mode 100644 tests/page-templates/00-basic/13-onload-minified.js diff --git a/boomerang.js b/boomerang.js index fdc376846..0fbc19df8 100644 --- a/boomerang.js +++ b/boomerang.js @@ -2608,7 +2608,7 @@ BOOMR_check_doc_domain(); * @memberof BOOMR */ real_sendBeacon: function() { - var k, form, url, errors = [], params = [], paramsJoined, varsSent = {}; + var k, form, url, errors = [], params = [], paramsJoined, varsSent = {}, _if; if (!impl.beaconQueued) { return false; @@ -2695,7 +2695,8 @@ BOOMR_check_doc_domain(); } if (w !== window) { - impl.vars["if"] = ""; + _if = "if"; // work around uglifyJS minification that breaks in IE8 and quirks mode + impl.vars[_if] = ""; } for (k in impl.errors) { diff --git a/plugins/compression.js b/plugins/compression.js index 3b23266bc..25690a922 100644 --- a/plugins/compression.js +++ b/plugins/compression.js @@ -127,11 +127,11 @@ /** * JSURL reserved value map */ - var JSURL_RESERVED = { - "true": true, - "false": false, - "null": null - }; + var _true = "true", _false = "false", _null = "null"; // work around uglifyJS minification that breaks in IE8 and quirks mode + var JSURL_RESERVED = {}; + JSURL_RESERVED[_true] = true; + JSURL_RESERVED[_false] = false; + JSURL_RESERVED[_null] = null; /** * Converts from JSURL to JSON. diff --git a/tests/page-template-snippets/boomerangDelayedSnippetNoScript.tpl b/tests/page-template-snippets/boomerangDelayedSnippetNoScript.tpl index 31010af0e..f083114ce 100644 --- a/tests/page-template-snippets/boomerangDelayedSnippetNoScript.tpl +++ b/tests/page-template-snippets/boomerangDelayedSnippetNoScript.tpl @@ -1,37 +1,3 @@ -(function(){ - if (window.BOOMR && window.BOOMR.version) { return; } - var dom,doc,where,iframe = document.createElement("iframe"),win = window; +window.BOOMR_script_delay = true; - function boomerangSaveLoadTime(e) { - win.BOOMR_onload=(e && e.timeStamp) || new Date().getTime(); - } - if (win.addEventListener) { - win.addEventListener("load", boomerangSaveLoadTime, false); - } else if (win.attachEvent) { - win.attachEvent("onload", boomerangSaveLoadTime); - } - - iframe.src = "javascript:void(0)"; - iframe.title = ""; iframe.role = "presentation"; - (iframe.frameElement || iframe).style.cssText = "width:0;height:0;border:0;display:none;"; - where = document.getElementsByTagName("script")[0]; - where.parentNode.insertBefore(iframe, where); - - try { - doc = iframe.contentWindow.document; - } catch(e) { - dom = document.domain; - iframe.src="javascript:var d=document.open();d.domain='"+dom+"';void(0);"; - doc = iframe.contentWindow.document; - } - doc.open()._l = function() { - var js = this.createElement("script"); - if (dom) { this.domain = dom; } - js.id = "boomr-if-as"; - js.src = "/delay?delay=3000&file=build/boomerang-latest-debug.js&rnd=" + Math.random(); - BOOMR_lstart=new Date().getTime(); - this.body.appendChild(js); - }; - doc.write(''); - doc.close(); -})(); +<%= boomerangSnippetNoScript %> diff --git a/tests/page-template-snippets/boomerangSnippetMin.tpl b/tests/page-template-snippets/boomerangSnippetMin.tpl new file mode 100644 index 000000000..03aac5186 --- /dev/null +++ b/tests/page-template-snippets/boomerangSnippetMin.tpl @@ -0,0 +1,3 @@ + diff --git a/tests/page-template-snippets/boomerangSnippetMinNoScript.tpl b/tests/page-template-snippets/boomerangSnippetMinNoScript.tpl new file mode 100644 index 000000000..159e7fdf1 --- /dev/null +++ b/tests/page-template-snippets/boomerangSnippetMinNoScript.tpl @@ -0,0 +1,3 @@ +window.BOOMR_script_minified = true; + +<%= boomerangSnippetNoScript %> diff --git a/tests/page-template-snippets/boomerangSnippetNoScript.tpl b/tests/page-template-snippets/boomerangSnippetNoScript.tpl index 0d81a2468..418f7a058 100644 --- a/tests/page-template-snippets/boomerangSnippetNoScript.tpl +++ b/tests/page-template-snippets/boomerangSnippetNoScript.tpl @@ -25,10 +25,18 @@ doc = iframe.contentWindow.document; } doc.open()._l = function() { - var js = this.createElement("script"); + var js = this.createElement("script"), prefix, suffix; if (dom) { this.domain = dom; } js.id = "boomr-if-as"; - js.src = "../../build/boomerang-latest-debug.js"; + if (window.BOOMR_script_delay) { + prefix = "/delay?delay=3000&file=build/"; + suffix = "&rnd=" + Math.random(); + } + else { + prefix = "../../build/"; + suffix = ""; + } + js.src = prefix + (window.BOOMR_script_minified ? "boomerang-latest-debug.min.js" : "boomerang-latest-debug.js") + suffix; BOOMR_lstart=new Date().getTime(); this.body.appendChild(js); }; diff --git a/tests/page-templates/00-basic/13-onload-minified.html b/tests/page-templates/00-basic/13-onload-minified.html new file mode 100644 index 000000000..8cd125663 --- /dev/null +++ b/tests/page-templates/00-basic/13-onload-minified.html @@ -0,0 +1,12 @@ +<%= header %> +<%= boomerangSnippetMin %> + + +<%= footer %> diff --git a/tests/page-templates/00-basic/13-onload-minified.js b/tests/page-templates/00-basic/13-onload-minified.js new file mode 100644 index 000000000..9511ba676 --- /dev/null +++ b/tests/page-templates/00-basic/13-onload-minified.js @@ -0,0 +1,95 @@ +/*eslint-env mocha*/ +/*global BOOMR_test,assert*/ + +describe("e2e/00-basic/13-onload-minified", function() { + var tf = BOOMR.plugins.TestFramework; + + it("Should have sent a beacon", function() { + // ensure we fired a beacon ('beacon') + assert.isTrue(tf.fired_onbeacon); + }); + + it("Should have fired 'beacon' with a beacon payload", function() { + // ensure the data was sent to 'beacon' + assert.isObject(tf.lastBeacon()); + }); + + it("Should have set basic beacon properties", function() { + assert.isString(tf.lastBeacon().v); + }); + + it("Should have set dom.* properties", function() { + assert.isNumber(tf.lastBeacon()["dom.img"], "dom.img"); + assert.isNumber(tf.lastBeacon()["dom.ln"], "dom.ln"); + assert.isNumber(tf.lastBeacon()["dom.script"], "dom.script"); + assert.isNumber(tf.lastBeacon()["dom.sz"], "dom.sz"); + + if (BOOMR_test.isResourceTimingSupported()) { + assert.isNumber(tf.lastBeacon()["dom.doms"], "dom.doms"); + assert.isNumber(tf.lastBeacon()["dom.res"], "dom.res"); + } + }); + + it("Should have set mem.* properties", function() { + if ((window.performance && window.performance.memory) || + (window.console && window.console.memory)) { + assert.isNumber(tf.lastBeacon()["mem.total"], "mem.total"); + assert.isNumber(tf.lastBeacon()["mem.used"], "mem.used"); + + // Might not exist except recent builds + if (tf.lastBeacon()["mem.limit"]) { + assert.isNumber(tf.lastBeacon()["mem.limit"], "mem.limit"); + } + } + }); + + it("Should have set RT properties", function() { + assert.isString(tf.lastBeacon().u, "u"); + + assert.isNumber(tf.lastBeacon()["rt.bstart"], "rt.bstart"); + assert.isNumber(tf.lastBeacon()["rt.end"], "rt.end"); + /* SOASTA PRIVATE START */ + assert.isString(tf.lastBeacon()["rt.si"], "rt.si"); + assert.isNumber(tf.lastBeacon()["rt.sl"], "rt.sl"); + assert.isNumber(tf.lastBeacon()["rt.ss"], "rt.ss"); + /* SOASTA PRIVATE END */ + assert.isString(tf.lastBeacon()["rt.start"], "rt.start"); + + // optional + if (typeof tf.lastBeacon()["rt.tstart"] !== "undefined") { + assert.isNumber(tf.lastBeacon()["rt.tstart"], "rt.tstart"); + } + }); + + it("Should have set scr.* properties", function() { + var s = window.screen; + assert.isString(tf.lastBeacon()["scr.bpp"], "scr.bpp"); + assert.isString(tf.lastBeacon()["scr.xy"], "scr.xy"); + + // only if we have orientation + if (s && s.orientation) { + assert.isString(tf.lastBeacon()["scr.orn"], "scr.orn"); + } + + // only if we have pixel ratio + if (window.devicePixelRatio && window.devicePixelRatio > 1) { + assert.isNumber(tf.lastBeacon()["scr.dpx"], "scr.dpx"); + } + }); + + it("Should have set LOGN / SOASTA properties", function() { + assert.isString(tf.lastBeacon()["h.key"], "h.key"); + }); + + it("Should have set vis.* properties", function() { + assert.isString(tf.lastBeacon()["vis.st"], "vis.st"); + }); + + it("Should have set Page ID (pid)", function() { + assert.isString(tf.lastBeacon().pid, "pid"); + }); + + it("Should have set nocookie=1", function() { + assert.equal(tf.lastBeacon().nocookie, "1"); + }); +});