Skip to content

Commit

Permalink
Work around minification that breaks in IE8 and quirks mode
Browse files Browse the repository at this point in the history
  • Loading branch information
querymetrics authored and nicjansma committed Apr 4, 2018
1 parent 61290ed commit 603d5da
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 45 deletions.
5 changes: 3 additions & 2 deletions boomerang.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions plugins/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 2 additions & 36 deletions tests/page-template-snippets/boomerangDelayedSnippetNoScript.tpl
Original file line number Diff line number Diff line change
@@ -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('<body onload="document._l();">');
doc.close();
})();
<%= boomerangSnippetNoScript %>
3 changes: 3 additions & 0 deletions tests/page-template-snippets/boomerangSnippetMin.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
<%= boomerangSnippetMinNoScript %>
</script>
3 changes: 3 additions & 0 deletions tests/page-template-snippets/boomerangSnippetMinNoScript.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
window.BOOMR_script_minified = true;

<%= boomerangSnippetNoScript %>
12 changes: 10 additions & 2 deletions tests/page-template-snippets/boomerangSnippetNoScript.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
12 changes: 12 additions & 0 deletions tests/page-templates/00-basic/13-onload-minified.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%= header %>
<%= boomerangSnippetMin %>
<script src="13-onload-minified.js" type="text/javascript"></script>
<script>
BOOMR_test.init({
ResourceTiming: {
enabled: false
},
testAfterOnBeacon: true
});
</script>
<%= footer %>
95 changes: 95 additions & 0 deletions tests/page-templates/00-basic/13-onload-minified.js
Original file line number Diff line number Diff line change
@@ -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");
});
});

0 comments on commit 603d5da

Please sign in to comment.