From 7e0edaff8016641db3e9a030079836da6beb12be Mon Sep 17 00:00:00 2001 From: Mantao Huang Date: Sun, 8 Mar 2026 00:30:00 -0600 Subject: [PATCH] Update setup instructions for uv and remove requirements.txt --- README.md | 20 +++++++++----------- requirements.txt | 1 - 2 files changed, 9 insertions(+), 12 deletions(-) delete mode 100644 requirements.txt diff --git a/README.md b/README.md index 61d837d..5390f39 100644 --- a/README.md +++ b/README.md @@ -11,22 +11,21 @@ This script elegantly solves the problem by: 2. Unpacking it from its `.crx` format. 3. Launching Chromium using Playwright in `--headless=new` mode (which DOES allow extensions, unlike the old headless mode) with a persistent user data directory. 4. Auto-closing setup tabs. -5. Emulating the official Zotero Connector keyboard shortcut (e.g. `Cmd+Shift+S` on Mac) once the page is fully loaded. +5. Invoking the Zotero Connector programmatically by accessing its background service worker (`Zotero.Connector_Browser.saveWithTranslator(...)`). ## Prerequisites -1. **Python 3.8+** installed. +1. [**uv**](https://github.com/astral-sh/uv) installed. 2. **Zotero Desktop** must be currently running on your machine (the extension communicates with the Zotero desktop app securely on port `1969`). ## Setup -First, initialize your virtual environment and install dependencies: +First, install dependencies and set up the playwright environment using `uv`: + ```bash -python3 -m venv venv -source venv/bin/activate -pip install -r requirements.txt -playwright install chromium +uv sync +uv run playwright install chromium ``` ## Usage @@ -34,17 +33,16 @@ playwright install chromium Simply pass the URL of the paper you want to add to Zotero: ```bash -source venv/bin/activate -python zotero_automator.py "https://arxiv.org/abs/1706.03762" +uv run zotero_automator.py "https://arxiv.org/abs/1706.03762" ``` If you want to watch the browser process visually (helpful for debugging if a site requires a captcha or login, or just to verify the extension is working), pass the `--headed` flag: ```bash -python zotero_automator.py "https://arxiv.org/abs/1706.03762" --headed +uv run zotero_automator.py "https://arxiv.org/abs/1706.03762" --headed ``` ## How It Works - **`setup_extension()`**: Locates the `EKHAGK...` identifier for the Zotero extension on the Chrome web store and downloads the raw `.crx` payload. It unpacks the contents into `./zotero_extension/`. -- **`save_to_zotero()`**: Starts an `async_playwright` session pointing to a local profile folder (`./chrome_profile/`). The extension injects its translator scripts on network idle. We fire the platform-specific shortcut for "Save to Zotero" and wait 10 seconds for the backend download to finish. +- **`save_to_zotero()`**: Starts an `async_playwright` session pointing to a local profile folder (`./chrome_profile/`). The extension injects its translator scripts on network idle. We find the extension's background service worker, trigger the programmatic save, and then poll `sessionProgress` until Zotero finishes downloading the PDFs and metadata. diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index e0a821a..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -playwright==1.42.0