commit 16b59d20c008ce6142375358bc2588b769cce718 Author: John Ogle Date: Mon Feb 17 11:05:45 2025 -0800 Initial commit diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..9e39478 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1739698114, + "narHash": "sha256-8S9n69Dnpg8DhfFlP0YvMGmSOY2X4kImGSPWXYNpaHM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b1b43d32be000928cc71250ed77f4a0a5f2bc23a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..24549dd --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "Development shell for google-cookie-retrieval"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + in { + devShells.${system}.default = pkgs.mkShell { + buildInputs = [ + pkgs.python3 + pkgs.python3Packages.selenium + pkgs.chromedriver + ]; + + shellHook = '' + echo "Development shell with Python, Selenium, and Chromedriver loaded." + ''; + }; + }; +} diff --git a/selenium_cookie_extractor_json.py b/selenium_cookie_extractor_json.py new file mode 100644 index 0000000..58c7bef --- /dev/null +++ b/selenium_cookie_extractor_json.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +import time +import json +from selenium import webdriver +from selenium.webdriver.chrome.service import Service + +# Configure Chrome options to run in incognito mode. +options = webdriver.ChromeOptions() +options.add_argument("--incognito") +# Uncomment the following option if you want to auto-open developer tools for each tab. +# options.add_argument("--auto-open-devtools-for-tabs") + +# Initialize the Chrome driver. +# If ChromeDriver is not in your PATH, specify its location: Service('/path/to/chromedriver') +service = Service() # Assumes chromedriver is in your PATH + +driver = webdriver.Chrome(service=service, options=options) + +print("Opening https://chat.google.com ...") +driver.get("https://chat.google.com") + +print("\nA new incognito window has been opened.") +print("Please log in normally. To inspect cookies manually:") +print(" 1. Press F12 to open developer tools.") +print(" 2. Navigate to the Application (Chrome) or Storage (Firefox) tab.") +print(" 3. Expand Cookies and select https://chat.google.com.") +print(" 4. Verify that the COMPASS, SSID, SID, OSID, and HSID cookies are present.") +print("\nIMPORTANT: Once you are logged in and have confirmed the cookies (or just logged in),") +print("press Enter here. (Remember: to keep the validity of these cookies, close the browser soon!)") +input("Press Enter to extract cookies...") + +# Get all cookies +all_cookies = driver.get_cookies() + +# Define the cookie names we want (case-insensitive) +target_names = {"compass", "ssid", "sid", "osid", "hsid"} +extracted = {} + +# For COMPASS cookie, if multiple are present, prefer the one with path == "/" +compass_cookie = None + +for cookie in all_cookies: + name_lower = cookie["name"].lower() + if name_lower in target_names: + # Process COMPASS cookie separately to pick the one with path '/' + if name_lower == "compass": + if cookie.get("path", "") == "/": + compass_cookie = cookie # select this cookie + elif not compass_cookie: + compass_cookie = cookie # take the first if none with '/' are found yet + else: + # For others, simply store the value + extracted[name_lower] = cookie["value"] + +# If we found a COMPASS cookie, add it to the extracted dict. +if compass_cookie: + extracted["compass"] = compass_cookie["value"] + +# Form JSON object of the extracted cookies. +json_data = json.dumps(extracted, indent=2) +print("\nExtracted Cookie JSON:") +print(json_data) + +print("\nPlease close the browser window soon to avoid invalidating the cookies (Google uses refresh tokens).") +time.sleep(5) # wait a few seconds to allow the user to read the output + +# Close the browser window. +driver.quit()