Skip to content

Commit

Permalink
Boomerang: Prerendered Support Part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ashenoy2014 authored and nicjansma committed Sep 25, 2024
1 parent dd0e88e commit 7b6ac2b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
4 changes: 3 additions & 1 deletion boomerang.js
Original file line number Diff line number Diff line change
Expand Up @@ -4946,13 +4946,15 @@ BOOMR_check_doc_domain();
getPrerenderedOffset: function(ts) {
var actSt = BOOMR.getActivationStart();

ts = Math.floor(ts);

if (actSt === false) {
// Prerender not supported or did not happen, return original timestamp
return ts;
}
else if (actSt !== null) {
// integer offset, return the difference
var newTs = Math.floor(ts) - actSt;
var newTs = ts - actSt;

// return the offset (at least 1ms)
return newTs >= 0 ? Math.max(1, newTs) : ts;
Expand Down
39 changes: 16 additions & 23 deletions plugins/rt.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,54 +793,47 @@
//

// Page Load time was 1ms
impl.timers.t_done = {
delta: 1
};
impl.timers.t_done = impl.timers.t_done || {};
impl.timers.t_done.delta = 1;

// Front-End Time was 1ms
impl.timers.t_page = {
delta: 1
};
impl.timers.t_page = impl.timers.t_page || {};
impl.timers.t_page.delta = 1;

// Back-End Time was 0
impl.timers.t_resp = {
delta: 0
};
impl.timers.t_resp = impl.timers.t_resp || {};
impl.timers.t_resp.delta = 0;
}
else {
//
// Activation before Page Load was complete
//

// Page Load needs to be offset by the difference
impl.timers.t_done = {
// loadEventEnd - navigationStart - activationStart
delta: (impl.timers.t_done.end - impl.cached_t_start - actSt)
};
// loadEventEnd - navigationStart - activationStart
impl.timers.t_done = impl.timers.t_done || {};
impl.timers.t_done.delta = (impl.timers.t_done.end - impl.cached_t_start - actSt);

if (actStEpoch > impl.timers.t_resp.end) {
// Activation after the Back-End was done

// Front-End Time was same as total Page Load Time
impl.timers.t_page = {
delta: impl.timers.t_done.delta
};
impl.timers.t_page = impl.timers.t_page || {};
impl.timers.t_page.delta = impl.timers.t_done.delta;

// Back-End Time was 0
impl.timers.t_resp = {
delta: 0
};
impl.timers.t_resp = impl.timers.t_resp || {};
impl.timers.t_resp.delta = 0;
}
else {
// Activation before Back-End was done

// Front-End Time stays the same

// Back-End Time was offset by Act St
impl.timers.t_resp = {
// reponseStart - navigationStart - activationStart
delta: (impl.timers.t_resp.end - impl.cached_t_start - actSt)
};
// reponseStart - navigationStart - activationStart
impl.timers.t_resp = impl.timers.t_resp || {};
impl.timers.t_resp.delta = (impl.timers.t_resp.end - impl.cached_t_start - actSt);
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ describe("e2e/28-rt/03-prerendered-activated-while-prerendering", function() {

assert.equal(tf.lastBeacon().t_resp, 0);
});

it("Should have set rt.end", function() {
assert.operator(tf.lastBeacon()["rt.end"], ">", 0);
});
});
21 changes: 20 additions & 1 deletion tests/test-templates/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,23 @@ describe("common", function() {
prefix = "ensure beacon " + (i + 1) + " ";

if (typeof b["rt.tstart"] !== "undefined" && typeof b["rt.end"] !== "undefined" && typeof b.t_done !== "undefined") {
assert.equal(parseInt(b["rt.end"]) - parseInt(b["rt.tstart"]), parseInt(b.t_done), prefix + "has rt.end - rt.tstart == t_done");
if (!t.isPrerenderingSupported() || !b.nt_act_st) {
assert.equal(parseInt(b["rt.end"]) - parseInt(b["rt.tstart"]), parseInt(b.t_done), prefix + "has rt.end - rt.tstart == t_done");
}
else {
// prerendering and activation_st exists.
if (b.nt_act_st > b["rt.end"]) {
// Activation happened after page load, so expect page load to be 1ms
assert.equal(1, parseInt(b.t_done), prefix + "Expected t_done to be 1ms");
}
else {
// Activation started before page load. Expect pageload to be offset by activationTime
var actTime = parseInt(b.nt_act_st, 10) - parseInt(b.nt_nav_st, 10);

// allow for rounding
assert.closeTo(parseInt(b.t_done), parseInt(b["rt.end"]) - parseInt(b["rt.tstart"]) - actTime, 1, "has (rt.end - rt.tstart) approximately close to t_done");
}
}
}

for (var j = 0; j < TIMERS.length; j++) {
Expand Down Expand Up @@ -583,6 +599,9 @@ describe("common", function() {
assert.closeTo(tm, now, (70 * 60 * 1000), prefix + "has " + param + " as a valid timestamp");
}
}

// rt.end should never be set to string "undefined"
assert.notEqual(b["rt.end"], "undefined", "rt.end should not be undefined");
}
});

Expand Down

0 comments on commit 7b6ac2b

Please sign in to comment.