Webviews, in-app browsers, and PWAs
Why a page loads differently inside apps: webviews and in-app browsers, installed web apps, Safari and iOS rules, and field data that says where each visit came from.
- 01Tell the in-app browsers apartKnow which ones bring their own empty storage, which share the browser's, and which let the app add scripts to your page.
- 02Make an installed launch fastWrite a manifest, let the service worker answer the launch, and know what installing changes on Android and on an iPhone.
- 03Measure visits from inside appsLabel each beacon with where it came from, and know what CrUX, Chrome, WebViews and WebKit can each report.
Asha taps a link in a chat app
In lesson 37.3, Ravi gave his Mint tea shop a service worker. Asha opened the shop in Chrome on her phone. Since then, it opens almost at once, even on the train.
Today her friend Ben sends her the link in a chat app. Asha taps it. The chat app doesn't open Chrome. It shows the shop inside itself. And the screen stays white for more than half a second.
Same phone. Same network. Same page. So why is the shop slow again? Here is what Asha saw at three moments after her tap, next to the same moments in Chrome:
Here are the numbers behind the frames:
// Asha opens Ravi's shop two ways, on the same phone and network. Times in ms.const visits = [ { where: "In the chat app", firstPaint: 652, photo: 1272, fromNetwork: 4, files: 4 }, { where: "In Chrome", firstPaint: 84, photo: 84, fromNetwork: 0, files: 4 },];for (const { where, firstPaint, photo, fromNetwork, files } of visits) { console.log(`${where}: first paint at ${firstPaint} ms, photo at ${photo} ms, ${fromNetwork} of ${files} files from the network`);}- Line 1 is a comment. A millisecond (ms) is a thousandth of a second.
- Lines 3 and 4 hold one visit each.
firstPaintis the moment anything appeared.photois the largest contentful paint, or LCP, from lesson 17.1. - Line 7 prints one line per visit.
- First:
In the chat app: first paint at 652 ms, photo at 1272 ms, 4 of 4 files from the network. - Then:
In Chrome: first paint at 84 ms, photo at 84 ms, 0 of 4 files from the network.
In Chrome, all four files came from the phone itself. The whole shop was there at 84 ms. In the chat app, all four came over the network. The photo took 1,272 ms, about 15 times longer.
The difference is where the page opened. The chat app showed it in a WebView: a browser engine that an app builds into its own screen. That WebView has storage of its own. It had never seen Ravi's shop, so it had no worker and no saved files. To the WebView, this was Asha's first visit.
At home, your cupboards are full, so a cup of tea takes a minute. A holiday flat has the same kind of kitchen, but its cupboards are empty. Before your first cup, you walk to the shop for tea and milk.
- In real life: Your kitchen at home, cupboards full
- In JavaScript: Chrome's storage: Ravi's worker and its cache
- In real life: The holiday flat's empty cupboards
- In JavaScript: The chat app's WebView, with storage of its own
- In real life: Walking to the shop for tea and milk
- In JavaScript: Downloading every file over the network
- In real life: The same recipe in both kitchens
- In JavaScript: The same page, on the same phone
Where a page opens decides what it starts with. A browser engine inside an app can bring its own empty storage, its own rules and its own reporting. So test each place your visitors open you, and label each visit in your field data. The next four sections take one question each: in-app browsers, installed web apps, iPhones, and measuring visits from inside apps.
How the course recorded it
- Ravi's shop: lesson 37.3's offline-first lighter page, with a manifest and a small script, rum.js, added in this lesson. A small Node server on the laptop served it.
- Asha's phone: Chrome 157, with the CPU 4 times slower, DevTools' Slow 4G, and a window 412 by 480 pixels, as in lesson 37.1.
- The chat app's WebView: Chrome with an empty profile, sending the user agent and the brand name a WebView sends.
- Chrome: the same phone, after an earlier visit had installed the worker. The worker was stopped first, as it is after a while.
- An iPhone: Playwright's WebKit 26.6, with Playwright's iPhone settings, at the laptop's full speed.
- Three of each: the visits took turns. The lesson quotes the middle one.
Webviews and in-app browsers
When you tap a link inside an app, the app decides where it opens. An in-app browser is any browser screen that opens inside the app. Phones have two kinds.
The app's own browser
- On Android, it's WebView. Android's docs say it shows a page with no address bar and no navigation buttons. JavaScript is even off until the app turns it on. Since Android 5, WebView gets its updates apart from Android's own.
- On an iPhone, it's WKWebView, WebKit's view for apps.
Both belong to the app. Chrome's docs say WebViews "don't share state with the browser". So an Android WebView keeps storage of its own, apart from Chrome's.
The browser, lent to the app
- On Android, it's a Custom Tab: the user's own browser, usually Chrome, shown inside the app. Chrome's docs list a "shared cookie jar and permissions model".
- On an iPhone, it's SFSafariViewController: Safari, shown inside the app.
So a Custom Tab would have opened Ravi's shop with Chrome's storage, worker and all. It would have looked like the Chrome row in the first picture. Here is who uses which storage on Asha's phone:
Why it matters: the same link cost Asha 1,272 ms or 84 ms, because of a choice the chat app made. Ravi can't make that choice for the app. He can keep his first visit small, as lesson 37.2 did.
Starting the browser before the tap
You finish your tea at a café. While you pay, you call a taxi and give the driver the address. When you step outside, the car is already at the door.
- In real life: Calling the taxi while you pay
- In JavaScript: warmup(): Chrome starts in the background
- In real life: Telling the driver the address
- In JavaScript: mayLaunchUrl(): the app names the likely link
- In real life: The car already at the door
- In JavaScript: The page opens with no wait for Chrome to start
Apps can do this with Custom Tabs. warmup() starts the browser in the background, before the tap. Chrome's docs say it "can save up to 700ms when opening a link". mayLaunchUrl() tells the browser which link is likely next, and the docs say it pre-fetches it. Both are calls in the app's own code. So it's the chat app's makers who can use them, not Ravi.
Scripts the app adds to your page
A WebView belongs to the app, so the app can run its own JavaScript in your page. On Android, addDocumentStartJavaScript runs a script in each page "when the document begins to load". On an iPhone, WKWebView's addUserScript does the same. For that, Chrome's docs send apps to a WebView, not a Custom Tab. And Apple says an app can't even see what happens in SFSafariViewController.
Added scripts run on your page's main thread, next to your own code. So they can slow your taps (lesson 26.1). The iOS developer Felix Krause built a page that shows them: InAppBrowser.com. Open it inside an iPhone app, and it lists the JavaScript that app ran in the page. In his tests, some popular social apps added their own code to the pages they opened.
Why it matters: if taps are slower inside one app, check what that app adds before you blame your code.
A shop's own app
A Trusted Web Activity is a Custom Tab with no browser bar at all. A shop can wrap its own site in an Android app this way. Chrome checks that the app and the site have the same owner. The app still can't read the page's cookies or storage.
Read each row across. It says who draws the page, whether the app can add scripts, and whether CrUX hears the visit. CrUX is Chrome's report of real visits, from lesson 10.1.
| How the app shows it | Who draws the page | Can the app add its own scripts? | Does CrUX hear it? |
|---|---|---|---|
| Android's WebView, inside the app | A copy of Chromium, updated apart from Android. It has its own storage, apart from Chrome's. | Yes. The app can run its own JavaScript in your page. | No. CrUX leaves out apps that use WebView. |
| A Chrome Custom Tab | Chrome itself, shown inside the app. It shares Chrome's cookies and storage. | No. Chrome's docs send apps that need that to a WebView. | Yes, from users who opted in. |
| An iPhone app's own WKWebView | WebKit, inside the app. It turns service workers off for most apps. | Yes, unless the app has turned on Apple's App-Bound Domains. | No. CrUX never hears from an iPhone. |
| SFSafariViewController on an iPhone | Safari, shown inside the app. | No. Apple says the app can't see what happens in it. | No. CrUX never hears from an iPhone. |
Installed web apps
Ravi has an idea. If Asha installs the shop on her home screen, she won't need a chat app to find it. A website people can install like an app is a progressive web app, or PWA. The system design lesson Progressive web apps covers the basics. Here, the question is speed. Does installing make the shop faster?
The manifest
To be installable, the shop needs a web app manifest: a small JSON file that describes the app. The page links to it with <link rel="manifest" href="manifest.webmanifest">. Here is Ravi's:
{ "name": "Leaf and Kettle", "short_name": "Leaf and Kettle", "start_url": "page.html", "display": "standalone", "background_color": "#fffdf8", "theme_color": "#2f5d46", "icons": [ { "src": "icon-192.png", "sizes": "192x192", "type": "image/png" }, { "src": "icon-512.png", "sizes": "512x512", "type": "image/png" } ]}- Lines 2 and 3 are the shop's names: the full one, and a short one for under the icon.
- Line 4,
start_url, is the page that opens when Asha taps the icon. - Line 5 asks for
standalone: a window of its own, with no address bar. - Line 6 colours the splash screen a phone shows while the app starts. Line 7 colours the app's toolbar.
- Lines 8 to 11 list the icons, cut from the tea photo.
What installing does on Android
On Android, Chrome turns an installed site into a WebAPK: a small Android app that opens the site in Chrome. web.dev says Chrome keeps using "the current profile" for its data. Cookies are shared, and "the service worker is installed and ready to go".
So when Asha taps the icon, Chrome opens start_url in a window of its own. Ravi's worker takes the request, with the same storage as in the Chrome row. Here is that Chrome visit again, timed with the worker asleep:
// Chrome opens the shop with the worker asleep. Times in ms, from the navigation entry and LCP.const nav = { workerStart: 2.1, fetchStart: 5.6 };const photo = 84;console.log(`The worker took ${(nav.fetchStart - nav.workerStart).toFixed(1)} ms to wake.`);console.log(`The photo was on screen at ${photo} ms.`);- Line 2 holds two recorded times from the navigation entry.
workerStartis when Chrome handed the request to the worker.fetchStartis when the worker was ready to take it (lesson 25.1). - Line 3 is the photo's LCP.
- It prints
The worker took 3.5 ms to wake.andThe photo was on screen at 84 ms.
The wake was quick because DevTools' CPU slowdown never reaches a worker, as lesson 25.1 showed. On a real phone, web.dev says a wake is more like 250 ms. That's still far below the WebView's 1,272 ms. Here are both openings, to scale:
Installing didn't make the shop faster by itself. The worker did, and the Chrome tab already had it. On Android, an installed launch is that same visit, in a window without an address bar.
You stick your favourite takeaway's number on the fridge. Ordering is now one call away. But the food comes from the same kitchen, just as fast as before.
- In real life: The number on the fridge
- In JavaScript: The icon on the home screen
- In real life: The dish you always order
- In JavaScript: start_url: the page that opens
- In real life: The same kitchen as before
- In JavaScript: Chrome's storage, with the same worker
- In real life: How fast the food comes
- In JavaScript: How fast the page loads
Why it matters: put your effort into the worker and the first visit, not into the install button. Pick a visit to see each time:
- First paint (FCP)652 ms
- Photo on screen (LCP)1,272 ms
- Files the worker answered0 of 4
- Downloaded by the page18 KB
- workerStart (0: no worker)0.0 ms
- fetchStart0.3 ms
- responseStart: the first byte563.3 ms
- Requests that reached Ravi's server6: page.html, rum.js, photo-800.jpg, page.js, sw.js, page.html
- The label in the beaconandroid-webview
The chat app's WebView had never seen the shop. Every file came over Slow 4G. After the load, the page installed a worker in the WebView's own storage, and that worker fetched what it keeps.
Knowing you're installed
A page can ask how it was opened. The display-mode media feature is browser in a tab, and standalone in an installed window. Ravi uses it to hide his install tip once the shop is installed:
.install-tip { margin: 4px 0 0; color: var(--accent); }@media (display-mode: standalone) { .install-tip { display: none; }}- Line 1 styles the tip under the heading: "Tip: add the shop to your home screen."
- Lines 2 to 4 hide it when
display-modeisstandalone.
In JavaScript, matchMedia("(display-mode: standalone)").matches asks the same question.
DevTools can't pretend
Can you test that in DevTools? The DevTools protocol has a command that fakes media features, such as dark mode. The course asked it to fake an installed window:
// DevTools asks Chrome to show the page as an installed app.await cdp.send("Emulation.setEmulatedMedia", { features: [{ name: "display-mode", value: "standalone" }] });// Then the page checks.matchMedia("(display-mode: standalone)").matches; // falsematchMedia("(display-mode: browser)").matches; // true- Line 2 asks Chrome to report standalone.
- Lines 4 and 5 are what the page answered: standalone was
false, and browser wastrue. The tip stayed on screen.
Chromium's code shows why. The list of features this command can change has seven entries, such as prefers-color-scheme (media_feature_overrides.cc, lines 118 to 140). display-mode isn't one of them. To see standalone, install the page for real. Chrome and Edge can install it on a laptop too, from the install icon in the address bar.
Safari and iOS differences
Ravi's own phone is an iPhone. On an iPhone, every browser uses WebKit, Safari's engine. Lesson 12.2 showed Apple's rule for that. Apple now allows other engines in two places, with its permission: the EU, from iOS 17.4, and Japan, from iOS 26.2. Everywhere else, Chrome on an iPhone is WebKit too.
What WebKit can measure
Ravi's rum.js asks each browser which entry types it can watch. Here are the two lists from the recording:
// What each engine listed in PerformanceObserver.supportedEntryTypes.const metrics = {"LCP": "largest-contentful-paint", "CLS": "layout-shift", "INP": "event", "LoAF": "long-animation-frame"};const listed = { "Chrome 157": ["element", "event", "first-input", "interaction-contentful-paint", "largest-contentful-paint", "layout-shift", "long-animation-frame", "longtask", "mark", "measure", "navigation", "paint", "resource", "soft-navigation", "visibility-state"], "WebKit 26.6": ["event", "first-input", "largest-contentful-paint", "mark", "measure", "navigation", "paint", "resource"],};for (const [engine, types] of Object.entries(listed)) { const can = Object.keys(metrics).filter((metric) => types.includes(metrics[metric])); console.log(`${engine} can measure ${can.join(", ")}`);}- Line 2 names the entry type behind each metric. INP comes from
evententries. LoAF is Long Animation Frames, from lesson 11.5. - Lines 4 and 5 are recorded: each engine's list.
- Line 8 keeps the metrics whose entry type is in the list.
- It prints
Chrome 157 can measure LCP, CLS, INP, LoAFandWebKit 26.6 can measure LCP, INP.
WebKit added LCP and INP in Safari 26.2. It still has no layout shifts and no Long Animation Frames. So an iPhone visit never sends a CLS. Lesson 12.2 showed why that's no answer, not 0. Compare the lists, and your own browser's:
- LCP: largest-contentful-paintyes
- CLS: layout-shiftyes
- INP: eventyes
- LoAF: long-animation-frameyes
- Your own marks: markyes
- Entry types in all15
- The whole listelement, event, first-input, interaction-contentful-paint, largest-contentful-paint, layout-shift, long-animation-frame, longtask, mark, measure, navigation, paint, resource, soft-navigation, visibility-state
It lists the entry types for all four metrics, and for your own marks.
Apps on an iPhone turn the worker off
In an ordinary iPhone app's own WKWebView, Ravi's worker never starts. WebKit's code turns service workers off there (WKWebView.mm, lines 894 to 899). They stay on in only three kinds of app:
- browsers;
- apps with a special permission from Apple;
- apps that limit their web view to a few domains of their own.
A chat app that opens any link is none of these. So inside it, the shop never gets the worker's help. The page always comes over the network, and with no signal it can't open at all.
Why it matters: on iPhones, the weight of the first visit counts even more.
Home Screen web apps
On iOS 26, anyone can add any site to the Home Screen from Safari's share menu. WebKit's notes say it then opens "as a web app" by default, with or without a manifest. In that window, display-mode is standalone. Apple's older check, navigator.standalone, is true there too.
But it starts empty. web.dev says each install on an Apple device "has its own isolated storage". So the first launch downloads every file and installs the worker again. Its storage does have one big advantage over Safari's.
Your gym empties any locker that isn't used for a week. Miss a week, and your things are gone, so you bring them all again. A cupboard at home stays as you left it.
- In real life: The gym locker
- In JavaScript: Safari's storage for Ravi's shop
- In real life: A week without a visit
- In JavaScript: Seven days of using Safari without opening the shop
- In real life: Bringing everything again
- In JavaScript: A cold load: every file over the network
- In real life: Your cupboard at home
- In JavaScript: A Home Screen web app's own storage
Safari's tracking prevention deletes a site's stored data "after seven days of Safari use without user interaction on the site". Its list includes "Service Worker registrations and cache". A Home Screen web app keeps its own count of days, from its own use. WebKit says it doesn't expect that app's data to be deleted.
Why it matters: on an iPhone, Ravi's worker lasts longest in a Home Screen web app.
Measuring inside apps
Ravi wants to know how often people open the shop inside apps, and how fast it is there. CrUX can't tell him. Its methodology counts Chrome on Android, "including mobile apps using Custom Tabs and WebAPKs". It leaves out "Android apps using WebView", and Chrome on iOS, as lesson 10.1 showed. So the chat app's 1,272 ms photo never reaches CrUX.
Ravi's own beacons can reach him. But each one needs a label that says where it came from.
Every letter gets a postmark from the post office it left. Read the postmarks on a pile of letters, and you know where they came from before you open them.
- In real life: A letter
- In JavaScript: One beacon
- In real life: The postmark
- In JavaScript: The where label
- In real life: Sorting the pile by postmark
- In JavaScript: Splitting field data by where
A label for every beacon
Here is Ravi's labelling function, from rum.js, run on what the three recorded visits read:
function whereFrom({ userAgent, brands, standalone }) { if (brands.includes("Android WebView") || userAgent.includes("; wv)")) return "android-webview"; if (standalone) return "installed"; if (/iPhone|iPad/.test(userAgent) && !userAgent.includes("Safari/")) return "ios-app-webview"; return "browser";} // What the three recorded visits read: the chat app's WebView, Chrome, and WebKit as an iPhone.const visits = [ { userAgent: "Mozilla/5.0 (Linux; Android 10; K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/157.0.0.0 Mobile Safari/537.36", brands: ["Chromium", "Android WebView"], standalone: false }, { userAgent: "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Mobile Safari/537.36", brands: ["Chromium", "Google Chrome"], standalone: false }, { userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6 Mobile/15E148 Safari/604.1", brands: [], standalone: false },];for (const visit of visits) console.log(whereFrom(visit));- Line 1: whereFrom takes three things the page can read. They are the user agent, the brand names, and whether the page runs installed.
- Line 2 finds an Android WebView. Chromium's WebView code puts "Android WebView" in the brand list (lines 53 to 56). It also adds
; wvto the user agent (lines 222 to 245). - Line 3 finds an installed app.
- Line 4 finds an iPhone app's own WKWebView. By default, WebKit ends its user agent with
Mobile/15E148, without Safari'sSafari/(WKWebViewConfiguration.mm, lines 532 to 539). - Line 5 calls everything else a browser tab.
- Lines 10 to 12 are recorded. Line 14 prints
android-webview,browserandbrowser.
The page reads those three things like this:
const where = whereFrom({
userAgent: navigator.userAgent,
brands: navigator.userAgentData?.brands.map((item) => item.brand) ?? [],
standalone: matchMedia("(display-mode: standalone)").matches || navigator.standalone === true,
});- Line 2 reads the user agent.
- Line 3 reads the brand names from
navigator.userAgentData. Safari and Firefox don't have it, so the list stays empty. - Line 4 checks
display-mode, andnavigator.standalonefor iPhones.
An app can change its WebView's user agent. Android's blog says the wv check works "unless an application has decided to override the User-Agent string". So a label is a good guess, not a promise. Try other strings here:
- brandsChromium, Google Chrome
- standalonefalse
- whereFrom saysbrowser
- The line that decidedline 5
Line 5: nothing else matched, so it's a browser tab, or something that looks like one.
What each beacon can carry
rum.js only watches the entry types the browser lists. When it can't measure a metric, it sends null. Ravi's server got these three beacons:
// The beacons Ravi's server received. Times in ms. null means "this browser can't measure it".const beacons = [ { from: "Chat app's WebView", where: "android-webview", lcp: 1272, cls: 0, inp: 40, photoLoaded: 1268 }, { from: "Chrome", where: "browser", lcp: 84, cls: 0, inp: 40, photoLoaded: 38 }, { from: "WebKit as an iPhone", where: "browser", lcp: 120, cls: null, inp: 16, photoLoaded: 16 },];for (const { from, where, lcp, cls, inp, photoLoaded } of beacons) { console.log(`${from}, ${where}: LCP ${lcp}, CLS ${cls ?? "none"}, INP ${inp}, photo loaded at ${photoLoaded}`);}- Lines 3 to 5 are recorded: one beacon from each visit.
- Line 8 prints
Chat app's WebView, android-webview: LCP 1272, CLS 0, INP 40, photo loaded at 1268. - Then
Chrome, browser: LCP 84, CLS 0, INP 40, photo loaded at 38. - Then
WebKit as an iPhone, browser: LCP 120, CLS none, INP 16, photo loaded at 16.
The WebView's beacon carried everything Chrome's did. Real WebViews can too: MDN's data lists LCP, layout shifts and INP for WebView on Android. WebKit sent no CLS. All three sent photoLoaded. That's a mark the photo sets when it loads, with onload="performance.mark('photo-loaded')". Marks come from User Timing, in lesson 11.6, and every engine here keeps them.
Notice what a mark measures. In Chrome, the photo had loaded at 38 ms, but it was painted at 84 ms. The mark says when the file arrived, not when it was drawn. Why it matters: in a browser that can't report a metric, your own marks still show when the important parts arrived.
Looking inside an app
You can debug a page inside an app only if the app allows it. On Android, chrome://inspect (from lesson 37.1) lists an app's WebViews once the app calls WebView.setWebContentsDebuggingEnabled(true). On an iPhone, Safari's Develop menu shows an app's WKWebView once the app sets isInspectable to true. Both are off unless the app turns them on. So in other people's apps, your beacons are your view inside.
Does CrUX hear this visit?
Each visit below opens Ravi's shop somewhere. Sort it by whether CrUX can ever hear it:
- Asha opens the shop in a Chrome tab on her Android phone
- A news app opens the shop in a Custom Tab
- Asha opens the installed shop from her home screen
- The chat app opens the shop in its own WebView
- Ravi opens the shop in Chrome on his iPhone
- Ravi opens the shop from his iPhone's Home Screen
- Someone opens the shop in Microsoft Edge on Android
- An iPhone chat app opens the shop in its own WKWebView
Sort each visit by whether CrUX can hear it.
Common mix-ups
- "A link opened in an app loads like a visit in Chrome." No. A WebView has storage of its own. The recorded shop took 1,272 ms there, and 84 ms in Chrome.
- "Installing the shop makes it faster." No. The worker made it fast. On Android, the installed shop uses Chrome's storage, worker included.
- "DevTools can make my page look installed." No. Its media override ignores
display-mode. Install the page to test it. - "My service worker runs in every iPhone app." No. WebKit turns workers off in most apps' own web views.
- "Safari keeps a service worker for ever." No. After seven days of Safari use without a visit, it can delete the worker and its cache.
- "CrUX includes visits from inside apps." No. It includes Custom Tabs and WebAPKs, but no WebViews and nothing on an iPhone.
Practice exercises
Answer first, then use the hints.
This is the user agent an iPhone app's own WKWebView sends by default. What does it print?
function whereFrom({ userAgent, brands, standalone }) {
if (brands.includes("Android WebView") || userAgent.includes("; wv)")) return "android-webview";
if (standalone) return "installed";
if (/iPhone|iPad/.test(userAgent) && !userAgent.includes("Safari/")) return "ios-app-webview";
return "browser";
}
const userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148";
console.log(whereFrom({ userAgent, brands: [], standalone: false }));ios-app-webview. It's Safari's string without Version/… and Safari/…, as an app's WKWebView sends it by default.
Asha opens the installed shop in Chrome on Android. What does it print?
function whereFrom({ userAgent, brands, standalone }) {
if (brands.includes("Android WebView") || userAgent.includes("; wv)")) return "android-webview";
if (standalone) return "installed";
if (/iPhone|iPad/.test(userAgent) && !userAgent.includes("Safari/")) return "ios-app-webview";
return "browser";
}
const userAgent = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Mobile Safari/537.36";
console.log(whereFrom({ userAgent, brands: ["Chromium", "Google Chrome"], standalone: true }));installed. Line 2 doesn't match Chrome, and standalone is true, so line 3 returns.
Someone moved a check for Safari/ to the top. This WebView sends no brands. What does it print now?
function whereFrom({ userAgent, brands, standalone }) {
if (userAgent.includes("Safari/")) return "browser";
if (brands.includes("Android WebView") || userAgent.includes("; wv)")) return "android-webview";
if (standalone) return "installed";
return "browser";
}
const userAgent = "Mozilla/5.0 (Linux; Android 10; K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/157.0.0.0 Mobile Safari/537.36";
console.log(whereFrom({ userAgent, brands: [], standalone: false }));if (brands.includes("Android WebView") || userAgent.includes("; wv)")) return "android-webview";browser. Chrome and WebView strings both end with Safari/537.36, so a Safari check that runs first catches the WebView too. Check for the WebView first, as rum.js does.
When Chrome opened the shop, when did the first byte of the page arrive, in ms?
7.2 ms. The worker was asked at 2.1 ms and ready at 5.6 ms. The page's first byte came from its cache a moment later.
Open Ravi's installable shop in Chrome. Wait a few seconds, then reload it. What does the Network panel's Size column say for the page itself?
(ServiceWorker). After the first load, the worker controls the page, so it answers the reload. DevTools' Network panel writes (ServiceWorker) in the Size column for any request a worker answered.
In the chat app's WebView, how many requests reached Ravi's server in all?
6: page.html, rum.js, photo-800.jpg, page.js, sw.js, page.html. The page asked for four files. Then the worker it installed in the WebView fetched sw.js and a fresh copy of the page for its cache. page.js, rum.js and the photo came from the HTTP cache.
Check your understanding
For each question, ask yourself where the page opened: a WebView, a Custom Tab, an installed window, or an iPhone.
Question 1 of 7Asha's Chrome has Ravi's service worker. Why did the shop still load from scratch in the chat app?
Choose an answer to see the explanation.
Question 2 of 7A news app opens Ravi's link in a Custom Tab. What does the page start with?
Choose an answer to see the explanation.
Question 3 of 7What does this check print for an app that adds its own name to WebView's user agent?
Read the code, then predictfunction whereFrom({ userAgent, brands, standalone }) { if (brands.includes("Android WebView") || userAgent.includes("; wv)")) return "android-webview"; if (standalone) return "installed"; if (/iPhone|iPad/.test(userAgent) && !userAgent.includes("Safari/")) return "ios-app-webview"; return "browser"; } const userAgent = "Mozilla/5.0 (Linux; Android 10; K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/157.0.0.0 Mobile Safari/537.36 ChatApp/5.2"; console.log(whereFrom({ userAgent, brands: [], standalone: false }));Choose an answer to see the explanation.
Question 4 of 7Ravi asks DevTools to show his page as installed, with setEmulatedMedia and display-mode: standalone. What does the page see?
Choose an answer to see the explanation.
Question 5 of 7An iPhone chat app opens Ravi's shop in its own WKWebView. Does the offline-first worker from lesson 37.3 help?
Choose an answer to see the explanation.
Question 6 of 7Ravi doesn't open his shop in Safari while he uses Safari on seven days. What can Safari do?
Choose an answer to see the explanation.
Question 7 of 7Ravi wants to know how fast the shop is inside chat apps on Android. Where can he find out?
Choose an answer to see the explanation.
Key takeaways
- Where a page opens decides what it starts with: Chrome's storage, or a WebView's own, empty the first time.
- Custom Tabs and SFSafariViewController lend the browser to the app. WebViews belong to the app, which can add its own scripts.
- On Android, an installed web app shares Chrome's storage, so its worker makes the launch fast. Installing alone doesn't.
- On an iPhone, it's all WebKit: LCP and INP but no CLS, no workers in most apps, and Home Screen apps with storage of their own.
- CrUX misses WebViews and iPhones. Label your own beacons with where each visit came from, and keep your own marks.
Remember the one-liner.
The same page starts with different things in different places: test each one, and label each visit with where it came from.
That ends Module 37, Every device and network. In lesson 37.1, Ravi slowed his laptop to match Asha's phone. In 37.2, he sent her a 15 KB page instead of 338 KB. In 37.3, he gave every request a time limit and kept the shop on her phone. Here, he found where that worker helps, and where it can't reach.
Sources
The facts on this page come from these specs, docs and source files:
- Build web apps in WebView, Android Developers.
- Overview of Android Custom Tabs, Chrome for Developers.
- Warm-up and pre-fetch: using the Custom Tabs Service, Chrome for Developers.
- Trusted Web Activity, Chrome for Developers.
- WebViewCompat: addDocumentStartJavaScript, Android Developers.
- WKUserContentController: addUserScript, Apple.
- SFSafariViewController, Apple.
- InAppBrowser.com: see what JavaScript commands get executed in an in-app browser, Felix Krause.
- Web Application Manifest, W3C.
- Add a web app manifest, web.dev.
- WebAPKs on Android, web.dev.
- Learn PWA: Installation, web.dev.
- media_feature_overrides.cc: what setEmulatedMedia can change, Chromium source.
- App Review Guidelines, Apple.
- Using alternative browser engines in the European Union, Apple.
- Using alternative browser engines in Japan, Apple.
- WebKit Features for Safari 26.2, WebKit.
- WKWebView.mm: service workers in apps, WebKit source.
- WebKit Features in Safari 26.0: every site can be a web app, WebKit.
- Safari Web Content Guide: Configuring Web Applications, Apple.
- Full Third-Party Cookie Blocking and More: the 7-day cap, WebKit.
- CrUX methodology, Chrome for Developers.
- User-Agent Reduction on Android WebView, Android Developers Blog.
- aw_content_browser_client.cc: WebView's user agent, Chromium source.
- aw_client_hints_controller_delegate.cc: WebView's brand, Chromium source.
- WKWebViewConfiguration.mm: an app's default user agent, WebKit source.
- Remote debug WebViews, Chrome for Developers.
- Enabling the Inspection of Web Content in Apps, WebKit.
- NetworkDataGridNode.ts: the Network panel's Size column, Chrome DevTools source.
Coming next: Performance and accessibility. How a fast page and an accessible page help each other.