This function returns the browser and os details
(request)
| 120 | |
| 121 | |
| 122 | def detect_browser(request): |
| 123 | """This function returns the browser and os details""" |
| 124 | electron_version = None |
| 125 | agent = request.environ.get('HTTP_USER_AGENT') |
| 126 | |
| 127 | try: |
| 128 | # available only for python 3.10 and above |
| 129 | os_release = platform.freedesktop_os_release() |
| 130 | os_details = os_release.get('PRETTY_NAME', '') |
| 131 | if os_details: |
| 132 | os_details += ', ' |
| 133 | except Exception as _: |
| 134 | os_details = '' |
| 135 | |
| 136 | os_details += parse(platform.platform()).ua_string |
| 137 | |
| 138 | if 'Electron' in agent: |
| 139 | electron_version = re.findall('Electron/([\\d.]+\\d+)', agent)[0] |
| 140 | |
| 141 | browser = re.findall( |
| 142 | '(opera|chrome|safari|firefox|msie|trident(?=/))/?\\s*([\\d.]+\\d+)', |
| 143 | agent, re.IGNORECASE) |
| 144 | if not browser: |
| 145 | browser = agent.split('/')[0] |
| 146 | else: |
| 147 | browser = " ".join(browser[0]) |
| 148 | |
| 149 | return browser, os_details, electron_version |