Open jimmywarting opened 7 years ago
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!
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
Thanks for the clarification, that's very helpful. The W3C Working Group will look into this and report back in this issue.
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)
those are some good use cases only different is my suggestion is based on power saving mode rather then a certain battery level
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?
@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.
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.
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.
@lucpotage, that sounds like a bug you should file for Chrome Android at https://crbug.com/new
Thank you for your suggestion. I got an answer from the team: https://bugs.chromium.org/p/chromium/issues/detail?id=804840
I think this is related: https://wicg.github.io/savedata/#save-data-request-header-field
@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
@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.
@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.
"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.
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.
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?
FYI the prefers-reduced-data
CSS media feature is in draft. Perhaps there could be something similar for a power saving mode?
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.
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.
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.
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.
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.
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?
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! 🤞
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.
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 https://github.com/w3c/battery/issues/56#issuecomment-1567269402
@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 🚀
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!
@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.
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