Detect if mobile chrome Data persistence feature is enabled with javascript

The Chrome mobile device on the Android device has a Data Retention option available from Settings> Data Retention.

When enabled, the behavior may be slightly different when reading media, especially video: on mobile videos, autoplay is disabled, except when video is disabled, but if data saving is disabled, disabled autoplay is no longer allowed.

I need a way to detect if data persistence is in use so that I can change the behavior of my player.

I know there is a header in HTTP requests: "save-data: on" But I don't know how to read HTTP headers from javascript.

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

Thanks for any answer.

+3


source to share


2 answers


I used this PHP to check if data-saver



/* 
* This is PHP Code 
* will not work on clicking "Run Code Snippet" 
* Host this code on php server as .php file 
*/

<?php
header('Content-Type: application/json');
$headers =  getallheaders();
$datasaver = false;
foreach($headers as $key=>$val){
    if(strtolower($key) == 'save-data' && $val == 'on'){
        $datasaver = true;
    }
}

$status = array('data-saver'=>$datasaver);

echo json_encode($status);

?>
      

Run codeHide result


As the website behaves differently when data-saver

enabled and there is no way to check through javascript to determine this. I have used PHP for now, but in the future we need to test it with javascript and I will update this thread if I convert it to javascript.

-1


source


You can determine if the user has enabled the save mode in Chrome, Opera or Yandex by looking for the request header save-data

. Dean Hume gives an example of how to define the save mode , although unfortunately his example uses an employee, so it won't work in Opera Mini.

Chrome Data Saver uses a proxy like some other Android browsers like Opera Mini in Extreme mode and UC Browser Mini for Android in speed mode.



You should also be able to look up the header X-Forwarded-For

to determine if Chrome's data compression proxying is being used .

-1


source







All Articles