deviceorientation alpha is wrong every time I turn off my screen

On an Android phone (in Chrome), I’m able to print the alpha orientation of the device with this simple event listener.

window.addEventListener("deviceorientation", function(event) {
   document.querySelector("#my-div").innerHTML = "Alpha: " + parseInt(event.alpha)
})

This works well, and I can see the value going from 0 to 360 as I’m spinning in my chair.

The problem: When I turn off and back on my screen, the value of alpha is offset by the angle I rotated the device during while the device was off. e.g. If I turned the screen off while alpha was 45° and I spin in my chair by 180 deg, when I turn my screen back on the value of alpha will still be around 45 and will keep being off by 180°.

Weird observation: If I open Google Maps, I can see the dot representing my position being gray for something like 2 seconds, then it turns back blue with the alpha angle pointing the real value. Going back to Chrome, the alpha value is now the same as in Google Maps, meaning the offset as been cleared somehow.

Any idea why the alpha value is wrong every time I turn the screen off?