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

Reestablish message port on bfcache restore #172

Merged
merged 2 commits into from
Mar 5, 2024
Merged
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
10 changes: 9 additions & 1 deletion src/browser_action/vitals.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
// Set up extension message port with the service worker
let port = chrome.runtime.connect();

// Re-establish the port connection on bfcache restore
window.addEventListener('pageshow', (event) => {
if (event.persisted) {
// The page is restored from BFCache, set up a new connection.
port = chrome.runtime.connect();
}
});

function initializeMetrics() {
let metricsState = localStorage.getItem('web-vitals-extension-metrics');
if (metricsState) {
Expand Down Expand Up @@ -302,7 +310,7 @@
metric.attribution.eventEntry) {
const subPartString = `${metric.name} sub-part`;
const eventEntry = metric.attribution.eventEntry;

let eventTarget = eventEntry.target;
// Sometimes the eventEntry has no target, so we need to hunt it out manually.
// As of web-vitals@3.5.2 `attribution.eventTarget` does the same thing,
Expand Down
Loading