Skip to content

Commit

Permalink
Support brands in user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfies committed Jan 10, 2025
1 parent 1633016 commit df7b52e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit df7b52e

Please sign in to comment.