From e6ebedbfcfe4f77f013cf77b0ba2a14c4c24e130 Mon Sep 17 00:00:00 2001 From: Andrew Ardill Date: Sat, 6 Jan 2024 16:02:01 +1100 Subject: [PATCH 1/2] cookies.py: Add support for Edge browser cookie retrieval --- aocd/cookies.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/aocd/cookies.py b/aocd/cookies.py index a57db51..7e04b37 100644 --- a/aocd/cookies.py +++ b/aocd/cookies.py @@ -48,9 +48,19 @@ def get_working_tokens() -> dict[str, str]: firefox = [c for c in firefox if c.name == "session"] log.info("%d candidates from firefox", len(firefox)) + log.info("checking edge cookie jar...") + try: + edge = bc3.edge(domain_name=".adventofcode.com") + except Exception as err: + log.debug("Couldn't scrape edge - %s: %s", type(err), err) + edge = [] + else: + edge = [c for c in edge if c.name == "session"] + log.info("%d candidates from edge", len(edge)) + # order preserving de-dupe - tokens = list({}.fromkeys([c.value for c in chrome + firefox])) - removed = len(chrome + firefox) - len(tokens) + tokens = list({}.fromkeys([c.value for c in chrome + firefox + edge])) + removed = len(chrome + firefox + edge) - len(tokens) if removed: log.info("Removed %d duplicate%s", removed, "s"[: removed - 1]) From 2c86f82c759f9808869d7b282373acce6aa64122 Mon Sep 17 00:00:00 2001 From: Andrew Ardill Date: Sat, 6 Jan 2024 16:06:18 +1100 Subject: [PATCH 2/2] README.rst: Add Edge to supported browsers for cookie retrieval --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index e38c4e6..85474f3 100644 --- a/README.rst +++ b/README.rst @@ -101,8 +101,8 @@ variable to some existing directory if you wish to use another location to store *New in version 0.9.0.* There's a utility script ``aocd-token`` which attempts to find session tokens from your browser's cookie storage. This feature is experimental -and requires you to additionally install the package ``browser-cookie3``. Only Chrome -and Firefox browsers are currently supported. On macOS, you may get an authentication +and requires you to additionally install the package ``browser-cookie3``. Only Chrome, +Firefox, and Edge browsers are currently supported. On macOS, you may get an authentication dialog requesting permission, since Python is attempting to read browser storage files. This is expected, the script *is* actually scraping those private files to access AoC session token(s).