Something like this?
https://learn.jquery.com/code-organization/feature-browser-detection/
You could create a JS function in Native Libraries and call it from python -
https://anvil.works/docs/client/javascript
JQuery is loaded by Anvil so is already available for you to use.