da2x / save-data

WebExtension for sending the Save-Data: on HTTP request header.
https://www.daniel.priv.no/web-extensions/save-data
GNU General Public License v3.0
21 stars 4 forks source link

Implement SaveData JavaScript API #1

Open da2x opened 6 years ago

da2x commented 6 years ago

Implement the following when dom.netinfo.enabled is flipped to true in Firefox beta

if ('connection' in navigator && navigator.connection.saveData === undefined)
{
  navigator.connection.saveData = true;
  navigator.connection.dispatchEvent(new Event('change'));
}
da2x commented 6 years ago

Work on the Network Information API was discontinued in 2014 and Firefox is unlikely to implement it. Google keeps recommending it to this day, however.

The following content script would partially implement it. However, this may cause more problems than it's worth as the rest of the Network Information API isn't implemented here.

let netinfo = navigator.connection || (navigator.connection = {});
netinfo.saveData = true;
if (netinfo.dispatchEvent)
  netinfo.dispatchEvent(new Event('change'));
PRR24 commented 3 years ago

Technically it should be proibably implemented as:

Object.defineProperty(navigator.connection, "saveData", { get: function() { return true; } });