Android WebView BackgroundSync is Disabled, How to Acivate it?

1,070 views
Skip to first unread message

Ádám Liszkai

unread,
Sep 1, 2016, 1:58:16 AM9/1/16
to Chromium-dev
Regarding the serviveWorker BackgroundSync you can run into the problem when the ServiceWorkerRegistration.sync.register('something')
is responging with: UnknownError: Background Sync is disabled.

I found that in WebView the BackgroundSync is disabled when no controller is available: https://bugs.chromium.org/p/chromium/issues/detail?id=570713

My question is that how can I enable the BackgroundSync in WebView?

Im using Android 5.1.1, the WebView using Chromium 52.0.2743.98. The background synchronization in webView are triggered with event what I trigger with an Android Service.

Details: http://stackoverflow.com/questions/39245088/android-webview-backgroundsync-is-disabled-how-to-acivate-it

Torne (Richard Coles)

unread,
Sep 1, 2016, 5:07:16 AM9/1/16
to adam...@gmail.com, Chromium-dev
It's disabled because it's not implemented for webview; there's no way to enable it. Things like background sync, notifications, etc are more complex for WebView to support because it's not its own application that can launch whenever it wants. We're looking at how to enable these in future, but it's not currently possible.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Liszkai Ádám

unread,
Sep 1, 2016, 5:23:48 AM9/1/16
to Torne (Richard Coles), Chromium-dev
:/ I understand the notifications and complex extensions should be disabled until it's implemented but the background sync is working as a "message" to the serviceWorker and it's do some code like when the worker install itself and return with a response for that. There is no periodicSyncManager right now in the platform which is a complex extension.

Anyway thanks for your reply, I will make a workaround, because simply I need syncronize data in the background.
--
Üdvözlettel: Liszkai Ádám,
Webfejlesztő, Programozó, Alkalmazásfejlesztő

Benoit Lize

unread,
Sep 1, 2016, 5:37:28 AM9/1/16
to adam...@gmail.com, Torne (Richard Coles), Chromium-dev
Hi,

Depending on what you want to achieve, you can consider using Custom Tabs (https://developer.chrome.com/multidevice/android/customtabs). It is not the right thing for your app in all situations though. If your entire app is based on Web technologies, you can also make it a pure web app, and make sure it's eligible to install prompts (https://developers.google.com/web/updates/2015/03/increasing-engagement-with-app-install-banners-in-chrome-for-android?hl=en).


Liszkai Ádám

unread,
Sep 1, 2016, 5:57:54 AM9/1/16
to Benoit Lize, Torne (Richard Coles), Chromium-dev
I only use webView for my webapp because I added a few monitoring solutions and I was not able to start fullscreen mode and take screenshot from the pwa. This app is working in industrial environment, not a public application and I need monitor the network and the application usage, and a few more stuff. I think tree way to workaround the problem:

1. sending Message instead registering sync to the serviceWorker
2. override the serviceWorker prototype so the background sync would work with a little trick
3. handle the syncronization in the android and send datas with the events

Anyway I will post the solution when I done with it :)

pichi pranav

unread,
Jul 23, 2018, 4:03:33 PM7/23/18
to Chromium-dev, li...@chromium.org, to...@chromium.org
Hi Adam,

Can you post the solution?

Davide Caruso

unread,
Aug 13, 2018, 4:14:39 PM8/13/18
to Chromium-dev, li...@chromium.org, to...@chromium.org
Hi Adam, I have the same problem reported in this topic. If you have found a solution, can you post it here?
Thanks 

Kshitij Banerjee

unread,
Jun 17, 2019, 11:20:25 AM6/17/19
to Chromium-dev, li...@chromium.org, to...@chromium.org
So - I also had the same issue and implemented 1. and it seems to be working for me. 

Here's the gist of it for anyone struggling with this. 

1. Use workbox background sync library. Create the plugin / queue as needed.
2. Use a broadcast message API to send a message to the service worker. 
3. Inside the message listener at the SW side, call replayRequests() on the queue / plugin._queue object. 

I tested this on a webview in android and seems to be working as of now. 
Reply all
Reply to author
Forward
0 new messages