MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / detect_browser

Function detect_browser

web/pgadmin/about/__init__.py:122–149  ·  view source on GitHub ↗

This function returns the browser and os details

(request)

Source from the content-addressed store, hash-verified

120
121
122def 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

Callers 1

indexFunction · 0.85

Calls 2

joinMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected