fix: return bare Google URL in referer instead of search query (#179)

Solves #172
This commit is contained in:
Karim shoair
2026-03-08 23:20:43 +02:00
committed by GitHub
2 changed files with 5 additions and 6 deletions
+4 -4
View File
@@ -20,13 +20,13 @@ chrome_version = 143
@lru_cache(10, typed=True)
def generate_convincing_referer(url: str) -> str | None:
"""Takes the domain from the URL without the subdomain/suffix and make it look like you were searching Google for this website
"""Generate a convincing Google referer header
>>> generate_convincing_referer('https://www.somewebsite.com/blah')
'https://www.google.com/search?q=somewebsite'
'https://www.google.com/'
:param url: The URL you are about to fetch.
:return: Google's search URL of the domain name, or None for localhost/IP addresses
:return: Google's URL as referer, or None for localhost/IP addresses
"""
# Fixing the inaccurate return type hint in `get_tld`
extracted: Result | None = cast(Result, get_tld(url, as_object=True, fail_silently=True))
@@ -43,7 +43,7 @@ def generate_convincing_referer(url: str) -> str | None:
if all(part.isdigit() for part in website_name.split(".") if part):
return None
return f"https://www.google.com/search?q={website_name}"
return "https://www.google.com/"
@lru_cache(1, typed=True)
+1 -2
View File
@@ -209,8 +209,7 @@ class TestFingerprintFunctions:
url = "https://sub.example.com/page.html"
result = generate_convincing_referer(url)
assert result.startswith("https://www.google.com/search?q=")
assert "example" in result
assert result == "https://www.google.com/"
def test_generate_convincing_referer_caching(self):
"""Test referer generation caching"""