Skip to content

Fix HTML5 battery API #24677

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

Merged
merged 1 commit into from
Jul 10, 2025
Merged

Fix HTML5 battery API #24677

merged 1 commit into from
Jul 10, 2025

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jul 9, 2025

The old navigator.battery API is not longer present in modern browsers which all use navigator.getBattery().

Tested locally on my laptop.

See https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager

@sbc100 sbc100 requested review from RReverser, kripken and juj and removed request for RReverser July 9, 2025 22:29
@sbc100
Copy link
Collaborator Author

sbc100 commented Jul 9, 2025

Alternatively I guess we should simply remove/deprecate this API since firefox removed it?

The old `navigator.battery` API is not longer present in modern
browsers which all use `navigator.getBattery()`.

Tested locally on my laptop.
batteryManager = b;
});
return {{{ cDefs.EMSCRIPTEN_RESULT_NO_DATA }}};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this API fails until the async part happens - that makes me wonder how useful this API is? Do you know of users?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also true for the emscripten_get_mouse_status API, so there is precedent, and that is what the EMSCRIPTEN_RESULT_NO_DATA result code is for I believe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, makes sense.

@sbc100 sbc100 enabled auto-merge (squash) July 10, 2025 00:03
@sbc100 sbc100 merged commit bb1ee9b into emscripten-core:main Jul 10, 2025
30 checks passed
@sbc100 sbc100 deleted the battery_api branch July 10, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants