Skip to content

Commit

Permalink
Reestablish message port on bfcache restore (#172)
Browse files Browse the repository at this point in the history
* Reestablish message port on bfcache restore

* Maybe I should uncomment the code fix :-)
  • Loading branch information
tunetheweb authored Mar 5, 2024
1 parent 2082064 commit fbbfcdf
Showing 1 changed file with 9 additions and 1 deletion.
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 [email protected] `attribution.eventTarget` does the same thing,
Expand Down

0 comments on commit fbbfcdf

Please sign in to comment.