summaryrefslogtreecommitdiffstats
path: root/g4f/cookies.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-11-19 20:26:00 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-11-19 20:26:00 +0100
commit1fe59623b22790dc2db36f106112795859bc6a25 (patch)
tree261867c0894205b5de213fc5816d6f405ea8759a /g4f/cookies.py
parentFix aliases to gui arguments (diff)
downloadgpt4free-1fe59623b22790dc2db36f106112795859bc6a25.tar
gpt4free-1fe59623b22790dc2db36f106112795859bc6a25.tar.gz
gpt4free-1fe59623b22790dc2db36f106112795859bc6a25.tar.bz2
gpt4free-1fe59623b22790dc2db36f106112795859bc6a25.tar.lz
gpt4free-1fe59623b22790dc2db36f106112795859bc6a25.tar.xz
gpt4free-1fe59623b22790dc2db36f106112795859bc6a25.tar.zst
gpt4free-1fe59623b22790dc2db36f106112795859bc6a25.zip
Diffstat (limited to 'g4f/cookies.py')
-rw-r--r--g4f/cookies.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/g4f/cookies.py b/g4f/cookies.py
index 8d535ce7..a43ccc86 100644
--- a/g4f/cookies.py
+++ b/g4f/cookies.py
@@ -15,6 +15,28 @@ try:
brave, edge, vivaldi, firefox,
_LinuxPasswordManager, BrowserCookieError
)
+
+ def _g4f(domain_name: str) -> list:
+ """
+ Load cookies from the 'g4f' browser (if exists).
+
+ Args:
+ domain_name (str): The domain for which to load cookies.
+
+ Returns:
+ list: List of cookies.
+ """
+ if not has_platformdirs:
+ return []
+ user_data_dir = user_config_dir("g4f")
+ cookie_file = os.path.join(user_data_dir, "Default", "Cookies")
+ return [] if not os.path.exists(cookie_file) else chrome(cookie_file, domain_name)
+
+ browsers = [
+ _g4f,
+ chrome, chromium, opera, opera_gx,
+ brave, edge, vivaldi, firefox,
+ ]
has_browser_cookie3 = True
except ImportError:
has_browser_cookie3 = False
@@ -114,7 +136,7 @@ def read_cookie_files(dirPath: str = None):
harFiles = []
cookieFiles = []
- for root, dirs, files in os.walk(CookiesConfig.cookies_dir if dirPath is None else dirPath):
+ for root, _, files in os.walk(CookiesConfig.cookies_dir if dirPath is None else dirPath):
for file in files:
if file.endswith(".har"):
harFiles.append(os.path.join(root, file))