Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if mobile chrome's Data saving feature is enable from javascript

In mobile chrome on android device, there is a setting called "Data saving" accessible from Settings > Data saving.

When enabled the behavior can be slightly different when reading media, especially video: on mobile autoplay videos are prohibited except if the video is muted but if data saving is enable muted autoplay isn't allowed anymore.

I would need a way to detect if data saving is used so I can change my video player behavior.

I know that there is a header sent in http requests: "save-data: on" But I don't know any way to read http requests header from javascript.

More info here: https://developer.chrome.com/multidevice/data-compression

Thanks for any answer.

like image 737
Guian Avatar asked Apr 05 '17 09:04

Guian


People also ask

How do I know if my browser is Chrome?

There are some optional window properties that that can be used when doing browser detection. One of them is the optional chrome property (Chromium) and the other the optional opr property (Opera). If a browser has the optional chrome property on the Window object, it means the browser is a Chromium browser.

Which browser can save data?

Opera Mini The browser can save up to 90% of your data when browsing the web. With a revamped look, user-friendly experience, and more functionalities, the latest version of Opera Mini allows you to customize your browse's layout, themes, navigation and more.


1 Answers

Javascript way to detect chrome data saver mode

if('connection' in navigator){
 if(navigator.connection.saveData){
  console.log(`Your save data mode is = ${navigator.connection.saveData}`)
 }else{
  console.log(`Your save data mode is = ${navigator.connection.saveData}`)
 }
}

For more details follow google developer blog post on Delivering fast and light applications with Save-Data

like image 87
Samar Panda Avatar answered Nov 06 '22 13:11

Samar Panda