This is by design, there is no way in JavaScript to detect if a hardware keyboard is connected or if a software keyboard is visible… because … Apple and Google don’t seem to think this is a problem that needs solving.
At least Google change the viewport size, Apple don’t even do that.