Skip to content

Add right-click capture to the ResearchOS Chrome extension - #22

Open
ThePyProgrammer wants to merge 4 commits into
mainfrom
feat/extension-context-menu-capture
Open

ThePyProgrammer wants to merge 4 commits into
mainfrom
feat/extension-context-menu-capture

Conversation

@ThePyProgrammer

Copy link
Copy Markdown
Owner

Summary

Add Save to ResearchOS to Chrome's right-click menu for pages, links, and selected DOIs/arXiv identifiers/URLs. Previously, saving a linked paper required opening it or copying its identifier into the popup. Users can now open the existing capture UI directly with the clicked target and remembered destination library, review it, and explicitly save to Inbox.

Closes #17. Follows the Chrome extension introduced in #16.

Screenshots

Actual capture windows rendered in Chromium using a local demo backend and a right-click link intent. The browser test exercises the session/window handoff; Chrome's native menu itself is not automated. The screenshots contain test data only.

Light mode Dark mode
Right-click capture in light mode Right-click capture in dark mode

Changes

  • Context-menu integration: Register a single Save to ResearchOS item for page, link, and selection contexts on installation/update, replacing previous entries to avoid duplicates. Add the contextMenus permission.
  • Correct capture target: Keep clicked links and selected identifiers separate from the containing page. Page clicks can read explicit scholarly metadata from the clicked frame where Chrome grants access; restricted pages/PDF viewers fall back to their original URL. Invalid selections remain editable instead of silently becoming a page capture.
  • Existing confirmation UI: Open the same themed capture interface in a small window, with the remembered library, type overrides, duplicate feedback, and existing import endpoints. Opening the window never automatically saves an item.
  • Independent capture windows: Give each window a separate session-stored target. Only an opaque capture ID appears in its URL. Closing the window removes its temporary target; an extension reload/browser restart clears session targets and prompts restored windows to capture again.
  • Error handling: Preserve the requested target through first-time connection setup, backend downtime, deleted libraries, and another active import. Missing capture IDs produce a recoverable message rather than substituting the current browser tab.
  • Tests and documentation: Add context-menu/unit/UI coverage, extend the Chromium test to verify session/window handoff and cleanup, and document usage and the new permission. Right-click capture moves from the future roadmap into current capabilities.

What is supported now

Task Behavior
Right-click a page Prefill its URL or scholarly identifier from page metadata where accessible.
Right-click a link Prefill the clicked target without importing the containing page.
Right-click a selected DOI/arXiv ID/URL Prefill that identifier; selected text takes precedence if selected inside a link.
Select unsupported text Show the original text and an explanation; saving stays disabled until corrected.
Confirm the destination Display the remembered library, permit changing it, and require an explicit Save to Inbox click.
Open multiple captures Keep each window's input independent while preserving the existing single-active-import guard.
Connect for the first time Keep the target while the user configures the backend.
Close a capture window Remove its temporary target; normal imports already submitted still run in the background.

This feature uses HTTP/HTTPS page contexts and the existing import pipeline. It does not add automatic capture, offline storage, local PDF upload, or persistent page-state badges. A backend must be available before an import can be submitted.

Potential future additions

These remain separate enhancement proposals rather than features included in this PR:

  1. Collections, tags, and capture notes.
  2. Batch capture from selected tabs and identifier lists.
  3. PDF attachment uploads without a public identifier.
  4. A capture queue for backend downtime, with safe retry semantics.

The extension README documents current capabilities and the broader roadmap.

Setup and database change

  1. From frontend, run npm run build:extension.
  2. Reload the unpacked extension at chrome://extensions and accept the added context-menu permission if Chrome requests it. For a fresh install, load frontend/extension/dist.
  3. Right-click a page, link, or selected identifier and choose Save to ResearchOS.
  4. Review the identifier, item type, and library, then click Save to Inbox.

No backend changes, API changes, new npm dependencies, or additional database migration are introduced. Migration 038 belongs to the already merged base extension work in #16.

Type of change

  • New feature
  • Documentation
  • Tests

Testing

  • All 466 frontend unit/UI tests passed with TZ=UTC, including 61 extension tests. The pre-existing dashboard chart test assumes UTC.
  • Context-menu coverage includes install/update replacement, event registration, page metadata, clicked links, selected identifiers, invalid selections, frame targeting, and PDF/restricted-page fallback.
  • Popup coverage includes explicit confirmation, remembered/deleted libraries, initial connection setup, unavailable backends, missing capture intents, and retaining a new target while another item is saving.
  • Capture-window tests cover isolated targets, opaque URL IDs, cleanup on close, and failed window creation.
  • The regular frontend and Chrome extension production builds passed.
  • The unpacked Chromium test passed, including menu registration, page/link/selection intent handoff, library selection, explicit save confirmation, import requests, window cleanup, and theme persistence. It also produced the screenshots above.
  • Chrome's native context-menu interaction and optional-permission dialog were not manually automated; native event handling is unit-tested and actual window/session behavior is exercised in Chromium.
  • The full existing app E2E smoke suite was not run locally for this follow-up; CI retains it alongside the extended extension test.

The browser test uses a disposable mock API and a disposable manifest with only its loopback host pre-granted. It does not contact a live ResearchOS database.

Review notes

  • The implementation/unit tests, browser validation/documentation, and screenshot update are separate focused commits.
  • Existing toolbar capture, keyboard shortcut, themes, duplicate handling, and import endpoints remain available.
  • The new capture flow sends no import request until the user confirms the target and library.

…ions

Register Save to ResearchOS on install/update and open the existing capture UI with the explicit target and remembered library. Isolate window targets in session storage, clean them up on close, and preserve save confirmation. Cover metadata fallbacks, invalid selections, deleted libraries, unavailable backends, and concurrent capture inputs. Refs #17.
Check menu registration and browser/session handoff for page, link, and selection captures, including explicit save confirmation and cleanup. Document right-click usage, temporary targets, and the contextMenus permission; move right-click capture out of the future roadmap. Native menu dispatch remains outside the headless browser test. Refs #17.
Capture the actual link-intent window in the Chromium flow with final theme colors. Add both screenshots to the extension guide so the right-click workflow can be reviewed alongside the original popup. Refs #17.
Keep session handoff fixtures aligned with the production page, link, and selection button labels. Assert each label and refresh the right-click screenshots with the correct link action.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] Chrome extension: right-click capture for pages, links, and selected DOIs

1 participant