react-native-device-info: Illegal invocation from getBattery call

Not 100% sure if this is actually an issue within this project, but though I would ask if someone happens to have some information on this.

Summary

Affected platform: web

Version 6.2.1
Affected OS all
OS Version No pattern

Current behavior

Some users apparently receive TypeError: Failed to execute 'getBattery' on 'Navigator': Illegal invocation. This is coming from react-native-device-info/lib/module/web/index.js in init. I did some research and error would indicate that the call is missing context (for navigator object), but based on code I have no idea how this could be. Perhaps the call should be prefixed with window.? So far we have had 156 users getting this error, so it seems pretty common although it does not happen to me. Screenshot 2021-04-21 at 9 24 22

Expected behavior

If getBattery call is found from navigator, call should not give error and no call should happen if method is not supported.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 19 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Issue still happening on react-native-device-info: ^10.4.0

🎉 This issue has been resolved in version 9.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

It would seem that my patch based on https://github.com/react-native-device-info/react-native-device-info/pull/1333 didn’t affect the error appearance rate, it’s still happening.

you seem to be working on every repo I use

Yeah, I probably shouldn’t 😆 but I really hate bugs. I really love fixing them though, and I extra-love it when anyone else helps fix bugs, it’s how the whole thing (react-native ecosystem) moves forward…

I’ve linked a PR @mikehardy (btw you seem to be working on every repo I use, RNfirebase, device-info… ^^)