Skip to content

Commit

Permalink
Continuity plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Apr 4, 2018
1 parent bda14f5 commit 0f1ced9
Show file tree
Hide file tree
Showing 82 changed files with 9,163 additions and 32 deletions.
138 changes: 135 additions & 3 deletions boomerang.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,19 @@ BOOMR_check_doc_domain();
* @event BOOMR#netinfo
* @property {object} connection `navigator.connection`
*/
"netinfo": []
"netinfo": [],

/**
* Boomerang event, subscribe via {@link BOOMR.subscribe}.
*
* Fired whenever a Rage Click is detected.
*
* This event will only happen if {@link BOOMR.plugins.Continuity} is enabled.
*
* @event BOOMR#rage_click
* @property {Event} e Event
*/
"rage_click": []
},

/**
Expand Down Expand Up @@ -1564,12 +1576,21 @@ BOOMR_check_doc_domain();
* @param {DOMElement} el DOM element
* @param {string} type Event name
* @param {function} fn Callback function
* @param {boolean} passive Passive mode
*
* @memberof BOOMR.utils
*/
addListener: function(el, type, fn) {
addListener: function(el, type, fn, passive) {
var opts = false;
if (el.addEventListener) {
el.addEventListener(type, fn, false);
if (passive && BOOMR.browser.supportsPassive()) {
opts = {
capture: false,
passive: true
};
}

el.addEventListener(type, fn, opts);
}
else if (el.attachEvent) {
el.attachEvent("on" + type, fn);
Expand All @@ -1595,6 +1616,9 @@ BOOMR_check_doc_domain();
var i;

if (el.removeEventListener) {
// NOTE: We don't need to match any other options (e.g. passive)
// from addEventListener, as removeEventListener only cares
// about captive.
el.removeEventListener(type, fn, false);
}
else if (el.detachEvent) {
Expand Down Expand Up @@ -1801,6 +1825,71 @@ BOOMR_check_doc_domain();
}

return "";
},

/*
* Gets the Scroll x and y (rounded) for a page
*
* @returns {object} Scroll x and y coordinates
*/
scroll: function() {
// Adapted from:
// https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY
var supportPageOffset = w.pageXOffset !== undefined;
var isCSS1Compat = ((w.document.compatMode || "") === "CSS1Compat");

var ret = {
x: 0,
y: 0
};

if (supportPageOffset) {
if (typeof w.pageXOffset === "function") {
ret.x = w.pageXOffset();
ret.y = w.pageYOffset();
}
else {
ret.x = w.pageXOffset;
ret.y = w.pageYOffset;
}
}
else if (isCSS1Compat) {
ret.x = w.document.documentElement.scrollLeft;
ret.y = w.document.documentElement.scrollTop;
}
else {
ret.x = w.document.body.scrollLeft;
ret.y = w.document.body.scrollTop;
}

// round to full numbers
if (typeof ret.sx === "number") {
ret.sx = Math.round(ret.sx);
}

if (typeof ret.sy === "number") {
ret.sy = Math.round(ret.sy);
}

return ret;
},

/**
* Gets the window height
*
* @returns {number} Window height
*/
windowHeight: function() {
return w.innerHeight || w.document.documentElement.clientHeight || w.document.body.clientHeight;
},

/**
* Gets the window width
*
* @returns {number} Window width
*/
windowWidth: function() {
return w.innerWidth || w.document.documentElement.clientWidth || w.document.body.clientWidth;
}

/* BEGIN_DEBUG */
Expand All @@ -1819,6 +1908,45 @@ BOOMR_check_doc_domain();

}, // closes `utils`

/**
* Browser feature detection flags.
*
* @class BOOMR.browser
*/
browser: {
results: {},

/**
* Whether or not the browser supports 'passive' mode for event
* listeners
*
* @returns {boolean} True if the browser supports passive mode
*/
supportsPassive: function() {
if (typeof BOOMR.browser.results.supportsPassive === "undefined") {
BOOMR.browser.results.supportsPassive = false;

if (!Object.defineProperty) {
return false;
}

try {
var opts = Object.defineProperty({}, "passive", {
get: function() {
BOOMR.browser.results.supportsPassive = true;
}
});
window.addEventListener("test", null, opts);
}
catch (e) {
// NOP
}
}

return BOOMR.browser.results.supportsPassive;
}
},

/**
* Initializes Boomerang by applying the specified configuration.
*
Expand Down Expand Up @@ -3403,6 +3531,10 @@ BOOMR_check_doc_domain();
m);
};
}
else {
// NOP for browsers that don't support it
boomr.log = function() {};
}

make_logger = function(l) {
return function(m, s) {
Expand Down
2 changes: 1 addition & 1 deletion doc/howtos/howto-resourcetiming-buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ so Boomerang doesn't make these changes automatically.

If you are using one of the Boomerang SPA plugins, the browser might hit the
150 limit quickly, as the browser will not clear the resources for SPA
navigtations. Therefore, you may want to increase the buffer size or clear the
navigations. Therefore, you may want to increase the buffer size or clear the
resources every time a beacon is sent.

The following code examples show how you can increase the limit, or clear the
Expand Down
1 change: 1 addition & 0 deletions plugins.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"plugins": [
"plugins/continuity.js",
"plugins/iframe-delay.js",
"plugins/auto-xhr.js",
"plugins/spa.js",
Expand Down
15 changes: 13 additions & 2 deletions plugins/auto-xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,15 @@
* @memberof BOOMR.plugins.AutoXHR
*/
function shouldExcludeXhr(anchor) {
if (anchor.href && anchor.href.match(/^(about:|javascript:|data:)/i)) {
return true;
if (anchor.href) {
if (anchor.href.match(/^(about:|javascript:|data:)/i)) {
return true;
}

// don't track our own beacons
if (anchor.href.indexOf(BOOMR.getBeaconURL()) === 0) {
return true;
}
}

return BOOMR.xhr_excludes.hasOwnProperty(anchor.href) ||
Expand Down Expand Up @@ -1117,6 +1124,10 @@

// increase the number of outstanding resources by one
current_event.nodes_to_wait++;

// ensure the timeout is cleared
this.clearTimeout();

// increase the number of total resources by one
current_event.total_nodes++;

Expand Down
Loading

0 comments on commit 0f1ced9

Please sign in to comment.