Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace load times #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
var loadTimes = window.chrome.loadTimes();
// send spdy info for current page
chrome.runtime.sendMessage({
spdy: loadTimes.wasFetchedViaSpdy,
info: loadTimes.npnNegotiatedProtocol || loadTimes.connectionInfo
});
var loadTimes = null;
function getLoadTimes() {
return loadTimes || (loadTimes = window.chrome.loadTimes());
}

chrome.runtime.onMessage.addListener(function (res, sender, sendResponse) {
function wasFetchedViaSpdy() {
// SPDY is deprecated in favor of HTTP/2, but this implementation returns
// true for HTTP/2 or HTTP2+QUIC/39 as well.
if (window.PerformanceNavigationTiming) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return ['h2', 'hq'].includes(ntEntry.nextHopProtocol);
}
return getLoadTimes().wasFetchedViaSpdy;
}

function connectionInfo() {
if (window.PerformanceNavigationTiming) {
// NPN is deprecated in favor of ALPN, but this implementation returns true
// for HTTP/2 or HTTP2+QUIC/39 requests negotiated via ALPN.
const ntEntry = performance.getEntriesByType('navigation')[0]
return ['h2', 'hq'].includes(ntEntry.nextHopProtocol) || ntEntry.nextHopProtocol
}
var loadTimes = getLoadTimes();
return loadTimes.wasNegotiatedProtocol || loadTimes.connectionInfo;
}

function sendInfo() {
chrome.runtime.sendMessage({
spdy: loadTimes.wasFetchedViaSpdy,
info: loadTimes.npnNegotiatedProtocol || loadTimes.connectionInfo
spdy: wasFetchedViaSpdy(),
info: connectionInfo()
});
}

// send spdy info for current page
sendInfo();

chrome.runtime.onMessage.addListener(function (res, sender, sendResponse) {
sendInfo();
});