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 deprecated chrome.loadTimes #41

Open
wants to merge 1 commit 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
33 changes: 27 additions & 6 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
var loadTimes = window.chrome.loadTimes();
// send spdy info for current page
function connectionInfo() {
if (window.PerformanceNavigationTiming) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return ntEntry.nextHopProtocol;
}
}
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);
}
}
function npnNegotiatedProtocol() {
// NPN is deprecated in favor of ALPN, but this implementation returns the
// HTTP/2 or HTTP2+QUIC/39 requests negotiated via ALPN.
if (window.PerformanceNavigationTiming) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return ['h2', 'hq'].includes(ntEntry.nextHopProtocol) ?
ntEntry.nextHopProtocol : 'unknown';
}
}
chrome.runtime.sendMessage({
spdy: loadTimes.wasFetchedViaSpdy,
info: loadTimes.npnNegotiatedProtocol || loadTimes.connectionInfo
spdy: wasFetchedViaSpdy(),
info: npnNegotiatedProtocol() || connectionInfo()
});

chrome.runtime.onMessage.addListener(function (res, sender, sendResponse) {
chrome.runtime.sendMessage({
spdy: loadTimes.wasFetchedViaSpdy,
info: loadTimes.npnNegotiatedProtocol || loadTimes.connectionInfo
spdy: wasFetchedViaSpdy(),
info: npnNegotiatedProtocol() || connectionInfo()
});
});