workbox-broadcast-update does not work inside android webview
See original GitHub issueLibrary Affected: workbox-broadcast-update (v6.3.0)
Browser & Platform: Webview for Android
Issue Description: I have a PWA application that is also inside an android webview in my app, and the broadcast update plugin does not send the update event with the StaleWhileRevalidate strategy. The exactly same build of PWA app with react performs diferently inside the webview and directly on chrome (on Chrome it works just fine).
navigator?.serviceWorker?.addEventListener('message', async event => {
if (event.data.meta === 'workbox-broadcast-update') {
/* eslint-disable */
if (confirm(`New app update is available!. Click OK to refresh`)) {
window.location.reload();
}
}
});
I added just a confirm call to test and on chrome it is been called but inside the webview it is not called. The confirm is just an extra test, The usual was to update the views with the new data, that works on chrome browser too, but also not in webview
The code to register the route is this one:
registerRoute(
({ url }) => url.pathname.startsWith('/my-url/v1/something'),
new StaleWhileRevalidate({
plugins: [new BroadcastUpdatePlugin()]
})
I don’t know if there is an issue at all, or the webview part is bad configured perhaps? But the service-worker and offline caching working just fine, only the broadcast update is not performing well.
On android side is just a webview
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
webview.settings.javaScriptEnabled = true
webview.settings.domStorageEnabled = true
webview.settings.setGeolocationEnabled(true)
webview.settings.mediaPlaybackRequiresUserGesture = false
webview.loadUrl(url)
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
🇧🇷 Oi Heitor!
I can see the message when using the example PWA you shared using WebView implementation in this gist: https://gist.github.com/andreban/40b22d321e4fc2de3f05f7753b8cd927.
The sample is a bit more involved than the one you shared, as it implements
onRenderProcessGone()
, which enables the app to recover to a potential WebView crash and also ensures that external links are handled in the user’s browser.However, I think that what may be making the difference here is the call to
webSettings.setDatabaseEnabled(true);
. Can you try this one out in your Android sample?CC: @andreban, my colleague whom I normally turn to for questions related to Android & the web. He might have some idea as to what’s going on.