Service Worker in android Webview

1,951 views
Skip to first unread message

Umar Ali

unread,
Mar 22, 2019, 10:10:51 AM3/22/19
to android-webview-dev
Hi,

       Recently I have been working on Webviews and found in chrome://inspect that if a webapp has Service Worker, it is shown as a separate webview in the inspect list. So my question is how do I get instance of that (Service Worker) webview so I can set its user-agent string and other settings.

P.S. I have to do this in Android M.

Thanks,

Umar Ali

Tim Volodine

unread,
Mar 22, 2019, 11:15:54 AM3/22/19
to Umar Ali, android-webview-dev, Toby Sargeant, Nate Fischer
For Android N and up, you can use ServiceWorkerController (and its settings) [1]. However I don't think we allow to set user agent on that.
For pre-N versions you can use AndroidX (support) library to get access to that api.

+cc:tobiasjs@ and ntfschr@ to potentially comment on AndroidX usage



--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
To post to this group, send email to android-w...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/c5780e83-f676-4a54-a783-23460f0d7b10%40chromium.org.

Torne (Richard Coles)

unread,
Mar 22, 2019, 12:04:41 PM3/22/19
to Tim Volodine, Umar Ali, android-webview-dev, Toby Sargeant, Nate Fischer
Yeah there isn't a WebView for the service worker, you can only control it using ServiceWorkerController as Tim mentions. It only has a limited set of APIs right now and it currently controls *all* service workers without distinguishing between which site they belong to. If you need additional APIs to control service workers, we'd love to know what your specific use cases are (you mentioned the user agent, but also "other settings" - which settings?) - probably the best thing to do is file a bug against webview on crbug.com explaining more information and we can take it as a feature request.

Reply all
Reply to author
Forward
0 new messages