-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reestablish message port on bfcache restore (#172)
* Reestablish message port on bfcache restore * Maybe I should uncomment the code fix :-)
- Loading branch information
1 parent
2082064
commit fbbfcdf
Showing
1 changed file
with
9 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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, | ||
|