From df7b52e371de6495cf624d32acea523bca228a9c Mon Sep 17 00:00:00 2001 From: dolfies Date: Fri, 10 Jan 2025 15:13:46 -0500 Subject: [PATCH] Support brands in user agent --- discord/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index e47745bf8ff5..11619a50be3e 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1760,10 +1760,14 @@ async def _get_browser_version( return int(data['versions'][0]['version'].split('.')[0]) @staticmethod - def _get_user_agent(version: int) -> str: + def _get_user_agent(version: int, brand: Optional[str] = None) -> str: """Fetches the latest Windows/Chrome user-agent.""" # Because of [user agent reduction](https://www.chromium.org/updates/ua-reduction/), we just need the major version now :) - return f'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{version}.0.0.0 Safari/537.36' + ret = f'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{version}.0.0.0 Safari/537.36' + if brand: + # e.g. Edg/v.0.0.0 for Microsoft Edge + ret += f' {brand}/{version}.0.0.0' + return ret # These are all adapted from Chromium source code (https://github.com/chromium/chromium/blob/master/components/embedder_support/user_agent_utils.cc)