WICG / proposals

A home for well-formed proposed incubations for the web platform. All proposals welcome.
https://wicg.io/
Other
233 stars 16 forks source link

Back/foraward cache NotRestoredReasons API #93

Closed rubberyuzu closed 8 months ago

rubberyuzu commented 1 year ago

Introduction

Currently developers can tell whether BFCache is being used or not but they cannot tell what reasons are blocking it from being used and what actions to take to improve their hit-rate. DevTools provide the testing feature to tell developers what reasons are blocking, but that is only for lab testing and not for gathering the data from the wild.

One way to solve this issue would be to provide an API to report the reasons why the page was not restored from bfcache if not. One idea is to extend PerformanceNavigation API to include this information as below:

window.addEventListener("pageshow", (event) => {
  if (!event.persisted) {
    const navEntries = performance.getEntriesByType("navigation");
    for (var i=0; i < navEntries.length; i++) {
    console.log("= Navigation entry[" + i + "]");
    var p = navEntries[i];
    // p.notRestoredReasons == [{url:"a.com", id: "x", blocked: true, reasons:["Broadcast channel"], children:[]}]
    }
  }
});

It will have notRestoredReasons field that will contain the reasons in the frame tree structure. Note that this would risk exposing cross-site information, so we should avoid reporting reasons from the cross-origin subframes.

Read the complete Explainer.

Feedback

I welcome feedback in this thread, but encourage you to file bugs against the Explainer.

rubberyuzu commented 1 year ago

Position requests for Mozilla and WebKit. This is the discourse discussion.

yoavweiss commented 1 year ago

Mozilla seems fine with this repo moving to the WICG org.

nicjansma commented 1 year ago

We would like to have notRestoredReasons for our RUM measurements in Akamai mPulse.

We are starting to track BFCache-based navigations, and with that our RUM customers will become more interested in why specific navs were not BFCache-eligable. Gathering this information will be a huge help in pointing out the culprits in aggregate.

yoavweiss commented 1 year ago

The repo is now live at https://github.com/WICG/bfcache-not-restored-reason

Happy incubation!!