[w3c/ServiceWorker] "display-mode" information on navigation requests (#1473)

This might be more related to fetch()/Request, rather than to ServiceWorker, but current situation hurts ServiceWorker usage and makes us use ServiceWorker hacks.

TLDR; Having a Display-Mode Client Hint would solve the problem.

**Requirement / Use Case**

Having a `isDisplayStandaloneRequest()` function on server-side for any data request: navigation & ajax.

Out website is old enough and it isn't server-rendering based. Many things are decided on navigation request time on server. What to show, what to hide. Some features are platform dependent, some aren't available to all browsers, etc. Same thing applied to browser's display mode. For example, when page is rendered in standalone mode, we would like to remove "Open in app" button from the menu. Other things may vary too, e.g. having navigation menu at the bottom, instead of the top, since in standalone nothing blocks / overlaps it.
Also it's important for analytics to distinguish between "display: standalone" page loads and normal page loads (many stats are saved on page requests, not on clients side afterwards).

**Implementation / Hacks**

The solution is somewhat possible with ServiceWorker, after all, SW is kinda required for a standalone PWA.

A possible solution would be to generate AppShell, load it on navigation requests, then send ajax request to get the data, including "display-mode" information with the request. There are few problems with that:
- Navigation preload won't work correctly with it
- To make an actual request to the network, we have to page for page and heavy JavaScript to execute, and only then send a request. i.e. it isn't possible to send data request to the network, from ServiceWorker, in parallel with page rendering
- Some pages of the website must be served without AppShell, they always must go to the server and render there

The last point could be somewhat fixed by first responding from SW with an "empty page" with small script which detects "display-mode" and does another navigation with such information in query string. This is actually terrible. Even though it isn't really visible in Chrome, because Chrome doesn't render white screens now, it Firefox URL Bar UI jumps because URL changes 3 times or so. Also I'm not even saying that it's hard to correctly implement giving whole lot of website redirects, downloads, etc. But it's what we have and use now.

**Solution / Suggestion**

I've been thinking for a while about this and I believe having a Client Hint / custom header for this would be a right solution. It would work for all the cases: navigation preload, normal requests and will be available in ServiceWorker (reading the header data in 'fetch' handler).

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1473

Received on Tuesday, 17 September 2019 03:33:58 UTC