Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect power saving mode #9

Open
jimmywarting opened this issue Mar 9, 2017 · 29 comments
Open

Detect power saving mode #9

jimmywarting opened this issue Mar 9, 2017 · 29 comments
Labels

Comments

@jimmywarting
Copy link

jimmywarting commented Mar 9, 2017

Some mobiles and laptop (even without batteries) have a power saving mode where they tune down on unnecessary stuff to save battery or reduce power consumption on stationary computers

I think it could be useful to detect this so we can disable some unnecessary stuff on the website

@anssiko
Copy link
Member

anssiko commented Mar 9, 2017

Thanks for your suggestion.

I assume you mean some sort of batterylow event that maps to a platform-specific battery level trigger? Would you prefer to have this as additional BatteryManager API surface, or as a standalone event?

It would be great to hear more specific use cases, i.e. how you would use such a feature in real-life web applications. That'd help make a case why the feature is important and should be standardized. You can drop some pseudo code if you like, or give pointers to existing projects that would benefit from this feature.

Thanks!

@jimmywarting
Copy link
Author

jimmywarting commented Mar 9, 2017

If i would want some sort of batterylow event trigger then i can do it on my own and just listen to the battery level change event and define my own set of rules. that is not really what i'm after

On my android phone i can turn on power saving mode whenever i want. Even if the battery is on 80%. This could be useful if i know i will be gone for a long time and won't be able to charge my phone for a while where i will spend time on my phone to pass my time (like on a airplain across the globe).

or when i'm laying in my bed before i go to sleep and spend some time on my phone and it pass below 15% it goes in to battery saving mode. but i can immediately turn it off again cuz i will soon go to sleep (just want to spend 10 more minutes to read my emails) and then charge my phone overnight

I would want something more like android's isPowerSaveMode() detection
https://developer.android.com/reference/android/os/PowerManager.html#isPowerSaveMode()

the power saving mode is more user controlled and not based on some batterylow event

@anssiko
Copy link
Member

anssiko commented Mar 9, 2017

Thanks for the clarification, that's very helpful. The W3C Working Group will look into this and report back in this issue.

@jimmywarting jimmywarting changed the title Detect battery saving mode Detect power saving mode Mar 9, 2017
@anssiko
Copy link
Member

anssiko commented Mar 9, 2017

It seems the use cases I documented a while ago are relevant here, adjusted slightly to map to the power saving mode:

  • App adjusts the amount/number of messages/tweets/data it fetches over the network as well as the polling frequency depending on the power saving mode state. If the user has put the device in power saving mode, the app will only poll for new data if the user explicitly interacts with the app and clicks the "Update" button. If the power saving mode is turned off, the app fetches data without user interaction.

  • App will only start an expensive (in terms of battery) operation that must run to completion if the device is not in power saving mode. For example, show a simpler map and not the fancy WebGL one if in power saving mode while using a web-based navigation app. (the navigation app knows how long it'll take to get to your destination, so can act accordingly).

  • App will only start a long-running irreversible operation if the power saving mode is turned off. For example, a very tedious checkout process, or an update of app assets (e.g. download of hi res textures for the new level in a web-based game).

The Web Budget API could be relevant to this discussion, but it is scoped to background operations.

(cc @beverloo @riju)

@jimmywarting
Copy link
Author

those are some good use cases only different is my suggestion is based on power saving mode rather then a certain battery level

@beverloo
Copy link
Member

I think @jimmywarting's suggestion makes sense— if the user explicitly requested apps on their device to save battery it'd be cool for Web apps to be able to help them do that. (The operating system and user agent already do this by e.g. batching or delaying push message delivery.)

I don't see any particular reason to limit the Budget API to background operations, modulo narrowing the scope to get the spec started. I do wonder about it's applicability in this case: the user agent can decide on the cost of an operation such as delivering a push message or giving Background Sync another try, because it's aware of its scope. The request in this issue is different in that it involves action by the developer: decreased WebGL quality, postponing arbitrary JavaScript work, and so on. It'll be difficult to fit the two in the same framework.

Instead, a very simple event (batterypreservingchange) +boolean (battery.preservingBattery) pair may be sufficient?

@anssiko anssiko added the v2 label Mar 16, 2017
@anssiko
Copy link
Member

anssiko commented Mar 16, 2017

@beverloo Thanks for the Budget API explainer!

We will look into adding another simple event to the Battery Status API to address this use case. I'll label this as "v2" to indicate this is a new feature under consideration.

@jimmywarting
Copy link
Author

jimmywarting commented Mar 16, 2017

Just a little note to why i changed the title:

jimmywarting changed the title from Detect battery saving mode to Detect power saving mode

I thought maybe what if the device don't have a battery and it still wants to use power saving mode?
He or she might want to reduce the cpu for some reason on a stationary computer?
I don't know if any stationary computer have this mode option but i believe there is somewhere

That's why i thought androids naming was a little better.
so instead of something like preservingBattery i think isPowerSaveMode was a little better.

@lucpotage
Copy link

When power save mode is active on Chrome Android, all videos stop playing automatically. Unfortunately, the browser does not provide a play button fallback because controls is not set as an attribute of the tag <video>. In iOS, they do show a play button in this case.

@anssiko
Copy link
Member

anssiko commented Jan 17, 2018

@lucpotage, that sounds like a bug you should file for Chrome Android at https://crbug.com/new

@lucpotage
Copy link

Thank you for your suggestion. I got an answer from the team: https://bugs.chromium.org/p/chromium/issues/detail?id=804840

@Malvoz
Copy link

Malvoz commented Feb 24, 2018

@jimmywarting
Copy link
Author

jimmywarting commented Feb 24, 2018

@Malvoz Not quite

due to high data transfer costs, slow connection speeds, or other reasons.

Saving data bandwidth and battery is not the same thing
it could be like if you are on a cellier plan and you would like to download a crappier version of a image/video to reduce the data usage but you could still have plenty of battery left

detecting power saving mode is more about saving power/battery. it would be more like: "Okey i should disable animations on the hole page in this offline application" or stop mining bitcoins

@js-choi
Copy link

js-choi commented Feb 24, 2018

@Malvoz Minimizing cellular-data use saves significant energy. In general, cellular antennae and transceivers are among the most energy-using/wasting hardware components of mobile devices.

@jimmywarting
Copy link
Author

jimmywarting commented Feb 25, 2018

@js-choi, true that. Reducing cellular-data saves some energy. But there are still other things that can draw lots of energy too. The screen is a big factor as well. Adjusting your app for AMOLEDs came to mind now.

  • Imagen having an all black and white e-reader.
  • or having a music equalizer stop rendering while playing offline music
  • you could release the screen look dose making the screen being able to idle.
  • you could have downloaded googles maps offline and used the navigations in airplain mode while driving a car in another country to save data roaming. You could save power by turning of the screen and only use the voice. imagen how it could work differently if you had 80+ battery or 15- when not having any network connection at all

"To me power saving mode and data saving are two different things."

Opera and Chrome has this thing where you can save data by allowing data to pass throught theres servers that compresses the data beforehand. That has nothing to do with power saving. I could have 95% battery but a crapy data plan or very little data left to use. Having data saving mode on dose not mean i want all my offline apps on my phone beginning to optimizing for power supply.

Turning on data saving mode could be like asking for best zip compression from a server but you know it will take longer time to generate and possible extra delay.

@josephscott
Copy link

I'd like to see a way to detect low power mode. As others have already noted, the existing data saver mode is related, but not exactly the same.

@noamr
Copy link

noamr commented Jul 13, 2020

Seeing that Apple has rejected battery API due to fingerprinting concerns (https://webkit.org/tracking-prevention/#table-of-contents-toggle:~:text=battery), I wonder if a slimmer version of the API can be thought of, mainly exposing very coarse yet useful information such as "are we currently in power saving mode" which can be used for meaningful optimizations.

WDYT?

@Malvoz
Copy link

Malvoz commented Jul 13, 2020

FYI the prefers-reduced-data CSS media feature is in draft. Perhaps there could be something similar for a power saving mode?

@gi11es
Copy link

gi11es commented Jul 13, 2020

Another use case to add to the list is that power saving mode greatly impacts the performance of a device. As such, it's useful information to know if the client is currently in power saving mode when you're collecting measurements from the Performance Timeline.

@Malvoz
Copy link

Malvoz commented Sep 7, 2020

Please see the related explainer by @chrishtr: https://github.com/chrishtr/battery-savings/blob/master/explainer.md, the proposal introduces "web page settings to save battery", which also entails detecting reduced framerate based on battery-savings settings.

@anssiko
Copy link
Member

anssiko commented Dec 9, 2022

I'm wondering whether the recently announced Energy Saver mode in Chrome would warrant reinvigorating this work? I think https://crbug.com/1308741 is related. Battery/Energy Saver mode features are part of many OSes too.

All - if there's still interest in this issue, please chime in with your latest use cases if possible and we take it from there. There's already a bunch of good use cases shared in this issue. Thanks to all contributors.

Looping in @beaufortfrancois since he did some (not directly related) exploration in #52 recently.

@anssiko
Copy link
Member

anssiko commented Dec 13, 2022

This issue is possibly relevant to @kenchris @cynthia interests.

TL;DR: this is a feature request to expose a power/battery saving mode state to web developers. Some interesting use cases shared in this issue.

@anssiko
Copy link
Member

anssiko commented Jan 27, 2023

I coalesced the ideas shared in this issue into an explainer document with some additional background: https://github.com/w3c/battery/blob/gh-pages/energy-saver-mode-explainer.md

Many thanks for your valuable feedback and suggestions.

@YutaMoriJP
Copy link

I coalesced the ideas shared in this issue into an explainer document with some additional background: https://github.com/w3c/battery/blob/gh-pages/energy-saver-mode-explainer.md

Many thanks for your valuable feedback and suggestions.

Thank you! That looks great! Not really familiar with the usual process, but what are the chances that will be approved and eventually made available to the Battery API?

@anssiko
Copy link
Member

anssiko commented Mar 6, 2023

Thanks for your feedback, @YutaMoriJP. The changes are further increased when web developers like you share their exciting use cases, support, feedback and suggestions in this issue. Thank you for your continued contributions! 🤞

@anssiko anssiko mentioned this issue May 29, 2023
@jimmywarting
Copy link
Author

some nit pick, while reading this code example:

let b = await navigator.getBattery();

if (b.energySaverMode) {
    saveEnergy();
}

b.energysavermodechange = () => {
    if (this.energySaverMode) saveEnergy();
}

I could not help but thinking: Hmm is energySaverMode a string or not? feels like energySaverMode could be either a "on" or "off" and not a boolean

I don't know how i feel about the r in saver at the end... just using save is good enough.

I like android / MacOS / iOS naming convention better.

  • isPowerSaveMode
  • lowPowerModeEnabled

It's a clear indication that it's a boolean. an alternative name could be energySaveModeOn or shouldPreserveEnergy
or how about using b.prefersEnergySaving in javascript as well? i would kind of like it if js & css had similar naming convention. i think i might like prefersEnergySaving the most.

also this code example:

- b.energysavermodechange = () => {
+ battery.onenergysavermodechange = () => {
    if (this.energySaverMode) saveEnergy();
}

Originally posted by @jimmywarting in #56 (comment)

@anssiko
Copy link
Member

anssiko commented May 29, 2023

@jimmywarting thanks for your feedback! Naming is hard and you provide great insights.

All - please keep the feedback coming and one day you may see this API 🚀

@sampittko
Copy link

sampittko commented Jun 15, 2023

At edi, we are building a no-code sustainable website builder. We would love to implement our low-mode feature for degradation of UI in a way that it is aware of this OS setting in addition to allowing a user to make their choice within the website. API that is being discussed in this thread would be very helpful for us in that matter!

@anssiko
Copy link
Member

anssiko commented Jun 15, 2023

@sampittko, thanks for your support and use case! The ethical web principles that inform W3C's work include considerations for sustainability (https://www.w3.org/TR/ethical-web-principles/#sustainable) and your product is well positioned to provide concrete feedback on how to improve existing Web APIs and what new Web APIs should be defined. Any additional feedback welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests