Just some further information for anyone reading this down the track. It looks as there is a new way of detecting a mobile device that is being phased in to replace the unwieldy use of the userAgent
string. As per this documentation there is now a boolean attribute of userAgentData
which detects whether the device is mobile.
From the Docs (referencing Java Script):
# If you are checking for mobile or desktop, use the boolean mobile value:
const isMobile = navigator.userAgentData.mobile;
If I am not mistaken, this would be the Anvil way to approach this
from anvil.js.window import navigator
is_mobile = navigator.userAgentData.mobile