Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions frontend/extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ These screenshots show the actual popup running in Chromium with a local demo ba
| --- | --- |
| ![ResearchOS capture popup in light mode](screenshots/popup-light.png) | ![ResearchOS capture popup in dark mode](screenshots/popup-dark.png) |

Right-click capture opens a separate window with the clicked target and destination library ready for confirmation:

| Light mode | Dark mode |
| --- | --- |
| ![Right-clicked link capture window in light mode](screenshots/context-capture-light.png) | ![Right-clicked link capture window in dark mode](screenshots/context-capture-dark.png) |

## Capabilities

| Capability | Current behavior |
| --- | --- |
| Capture the current page | Prefills from the active tab's URL, selected identifier, or explicit scholarly metadata. |
| Capture with a right-click | Opens the same capture UI in a small window for the clicked page, link, or selected identifier; waits for you to confirm Save. |
| Paste an identifier | Accepts DOIs, arXiv IDs, and HTTP/HTTPS URLs independently of the current page. |
| Choose an item type | Automatically detects papers, websites, and GitHub repositories, with manual type overrides. |
| Choose a destination | Saves new items to Inbox in the selected ResearchOS library. |
Expand Down Expand Up @@ -48,6 +55,9 @@ Rebuild and click **Reload** on `chrome://extensions` after changing the source.
## Capturing research

- Click the toolbar icon or press **Alt+Shift+S** to open the popup. Customize the shortcut at `chrome://extensions/shortcuts`.
- Right-click a web page, link, or selected DOI/arXiv identifier/URL and choose **Save to ResearchOS**. A small capture window shows that target and your last saved library. Review it and click **Save to Inbox**; opening the window does not import anything automatically.
- Right-clicked links and selections take precedence over the containing page. Invalid selections stay in the input with an explanation so you can correct them. Page captures can use scholarly metadata, including metadata inside a clicked frame where Chrome allows access.
- Each right-click capture has its own temporary target, so opening another capture does not replace one you are reviewing. Closing the capture window clears that target; browser restart or extension reload clears all temporary targets. A capture window restored after that asks you to capture again.
- The extension uses the current page's URL and explicit scholarly metadata such as `citation_doi`. A selected DOI, arXiv identifier, or URL takes precedence.
- Paste an identifier or URL to save something other than the current page.
- **Auto** recognizes DOI/arXiv, OpenReview, Zenodo, PDF and GitHub links. Use **Paper** for publisher pages without scholarly metadata, **Website** to keep a page as a website, or **GitHub** for a repository. Chrome-internal pages and local files cannot be captured; paste a public identifier instead.
Expand All @@ -61,7 +71,7 @@ The backend writes to the same Supabase database configured for your ResearchOS

The extension follows this repository's current unauthenticated backend API. Deployments behind an additional sign-in proxy or custom token authentication need a corresponding authentication integration; this extension does not copy browser sessions or store database keys.

Required permissions are `activeTab`, `scripting`, and `storage`. Page metadata is read only when opening the popup. Server access is requested for the configured hostname on connection; Chrome host permissions cover that host's ports, but fetches use the exact configured URL. No permanent access to every page, browsing history, third-party fonts, or analytics is requested. Only the identifier/URL and library ID are sent to ResearchOS. The backend's usual metadata and AI behavior still applies.
Required permissions are `activeTab`, `scripting`, `storage`, and `contextMenus`. Page metadata is read only when you open the toolbar popup or choose to capture a page from the context menu. Link/selection captures use the explicit target without reading the containing page's metadata. Temporary right-click targets live in extension session storage and are removed when their capture window closes. Server access is requested for the configured hostname on connection; Chrome host permissions cover that host's ports, but fetches use the exact configured URL. No permanent access to every page, browsing history, third-party fonts, or analytics is requested. Only the identifier/URL and library ID are sent to ResearchOS. The backend's usual metadata and AI behavior still applies.

If a request loses its connection, times out, or the browser stops during a save, the result may be uncertain even if ResearchOS completed the import. Check Inbox before retrying. The extension never automatically replays a write. Requests time out after 25 seconds to respect Chrome's service-worker fetch limit.

Expand All @@ -71,7 +81,6 @@ These are ideas for later work, not capabilities included in this release. The o

| Addition | What it would enable | Implementation considerations |
| --- | --- | --- |
| Right-click capture | Save a page, link, or selected DOI from Chrome's context menu. | Add the context-menu permission and reuse detection and import handling. |
| Collections, tags, and capture notes | File an item and record why it matters while saving. | Load library-scoped collections and define how annotations apply to existing duplicates. |
| Batch capture | Import selected tabs, bookmarks, or a pasted list of identifiers. | Show per-item progress, cancellation, duplicate review, and rate limits. |
| PDF attachment upload | Upload a local or already-open PDF when a DOI or public paper link is unavailable. | Use the app's PDF metadata and upload flow, with explicit file selection and size limits. |
Expand All @@ -93,6 +102,6 @@ npx playwright install chromium
npm run test:extension
```

The browser test loads a disposable copy of the built Manifest V3 extension in Chromium and uses a local mock API, without contacting your database. It grants only the mock server's host in that disposable copy, since headless Chromium cannot display Chrome's native optional-permission prompt. It verifies service-worker imports for all three item types, library selection, duplicate handling, real script injection, theme persistence, and light/dark screenshots. The shipped manifest retains optional server access only. Browser output is under `frontend/test-results/extension`.
The browser test loads a disposable copy of the built Manifest V3 extension in Chromium and uses a local mock API, without contacting your database. It grants only the mock server's host in that disposable copy, since headless Chromium cannot display Chrome's native optional-permission prompt. It verifies service-worker imports for all three item types, library selection, duplicate handling, real script injection, theme persistence, and light/dark screenshots. It also checks menu registration and capture-window/session handoff for page, link, and selection intents, including explicit save confirmation and cleanup. Context-menu event handling and target extraction are covered by unit tests rather than automating Chrome's native menu. The shipped manifest retains optional server access only. Browser output is under `frontend/test-results/extension`.

Chrome references: [host permissions and network requests](https://developer.chrome.com/docs/extensions/develop/concepts/network-requests), [runtime permission requests](https://developer.chrome.com/docs/extensions/reference/api/permissions), and [service worker lifecycle](https://developer.chrome.com/docs/extensions/develop/concepts/service-workers/lifecycle).
46 changes: 46 additions & 0 deletions frontend/extension/e2e/extension.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,52 @@ test('unpacked extension connects, imports all item types, handles duplicates, a
await expect(popup.getByRole('heading', { name: 'Save to Inbox' })).toBeVisible()
await expect(popup.getByLabel('Save to library')).toHaveValue('lib_2')
await expect(popup.getByLabel('Color theme')).toHaveValue('dark')

// Context-menu event handling and target extraction are covered in contextMenu.test.
// Here exercise the browser/session/window handoff with each resulting intent.
await worker.evaluate(async () => {
await chrome.contextMenus.update('researchos-save-to-inbox', { title: 'Save to ResearchOS' })
})
for (const [contextType, identifier, type, reason] of [
['selection', '10.1000/context-selection', 'paper', 'Selected text'],
['link', 'https://example.org/linked-article', 'website', 'Right-clicked link'],
['page', '10.1000/context-page', 'paper', 'Current page'],
]) {
const previousImports = imported.length
const opened = context.waitForEvent('page')
const captureId = await worker.evaluate(async capture => {
const id = crypto.randomUUID()
const key = `researchos.contextCapture.${id}`
await chrome.storage.session.set({ [key]: capture })
const window = await chrome.windows.create({ url: chrome.runtime.getURL(`popup.html?capture=${id}`), type: 'popup', width: 420, height: 680 })
await chrome.storage.session.set({ [key]: { ...capture, windowId: window.id } })
return id
}, { context: contextType, identifier, page: { title: identifier }, source: {
type, identifier, reason,
buttonLabel: { page: 'Use this page', link: 'Use this link', selection: 'Use this selection' }[contextType],
}, error: '' })
const captureWindow = await opened
await expect(captureWindow.getByRole('heading', { name: 'Save to Inbox' })).toBeVisible()
await expect(captureWindow.getByLabel('DOI, arXiv ID, or URL')).toHaveValue(identifier)
await expect(captureWindow.getByLabel('Save to library')).toHaveValue('lib_2')
await expect(captureWindow.getByText(reason)).toBeVisible()
await expect(captureWindow.getByRole('button', { name: { page: 'Use this page', link: 'Use this link', selection: 'Use this selection' }[contextType] })).toBeVisible()
expect(imported.length).toBe(previousImports)
if (contextType === 'link') {
for (const theme of ['light', 'dark']) {
await captureWindow.getByLabel('Color theme').selectOption(theme)
await captureWindow.locator('#root').screenshot({ path: testInfo.outputPath(`context-capture-${theme}.png`), animations: 'disabled' })
}
}
await captureWindow.getByRole('button', { name: 'Save to Inbox', exact: true }).click()
await expect(captureWindow.getByText('Saved to Inbox', { exact: true })).toBeVisible()
expect(imported.at(-1)).toEqual({
path: type === 'paper' ? '/api/papers/import' : '/api/websites/import',
body: { [type === 'paper' ? 'identifier' : 'url']: identifier, library_id: 'lib_2' },
})
await captureWindow.close()
await expect.poll(() => worker.evaluate(async id => (await chrome.storage.session.get(`researchos.contextCapture.${id}`))[`researchos.contextCapture.${id}`], captureId)).toBeUndefined()
}
expect(errors).toEqual([])
} finally {
await context?.close()
Expand Down
2 changes: 1 addition & 1 deletion frontend/extension/public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Save papers, DOIs, websites, and GitHub repositories to your ResearchOS Inbox.",
"version": "0.1.0",
"minimum_chrome_version": "109",
"permissions": ["activeTab", "scripting", "storage"],
"permissions": ["activeTab", "scripting", "storage", "contextMenus"],
"optional_host_permissions": ["http://*/*", "https://*/*"],
"action": {
"default_popup": "popup.html",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 16 additions & 7 deletions frontend/src/extension/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,30 @@ export default function App() {
let alive = true
async function start() {
try {
const [state, currentPage] = await Promise.all([command('GET_STATE'), captureActivePage().catch(() => null)])
const captureId = new URLSearchParams(window.location.search).get('capture')
const captureRequest = captureId !== null
? command('GET_CONTEXT_CAPTURE', { id: captureId }).catch(err => ({ identifier: '', error: err.message }))
: captureActivePage().then(currentPage => ({
page: currentPage,
source: currentPage ? sourceFromPage(currentPage) : null,
})).catch(() => ({}))
const [state, capture] = await Promise.all([command('GET_STATE'), captureRequest])
if (!alive) return
setSettings(state.settings)
setLibraryId(state.settings.libraryId)
setRecent(state.recent || [])
const source = currentPage ? sourceFromPage(currentPage) : null
setPage(currentPage)
const source = capture.source
setPage(capture.page)
setPageSource(source)
if (state.job?.status === 'saving') {
if (capture.error) setError(capture.error)
if (state.job?.status === 'saving' && captureId === null) {
setIdentifier(state.job.identifier)
setLibraryId(state.job.libraryId)
setJob(state.job)
} else {
setIdentifier(source?.identifier || '')
if (state.job && (['error', 'uncertain'].includes(state.job.status) || state.job.identifier === source?.identifier)) setJob(state.job)
setIdentifier(capture.identifier ?? source?.identifier ?? '')
if (state.job && (state.job.status === 'saving' || state.job.identifier === (capture.identifier ?? source?.identifier) ||
(captureId === null && ['error', 'uncertain'].includes(state.job.status)))) setJob(state.job)
}
if (state.settings.connected) {
try {
Expand Down Expand Up @@ -183,7 +192,7 @@ export default function App() {
<div><h1 className="text-lg font-semibold tracking-tight text-slate-900">Save to Inbox</h1><p className="mt-1 text-xs text-slate-500">Keep a paper, a page, or your next idea.</p></div>
{pageSource && <div className="flex items-start gap-3 rounded-xl border border-slate-200 bg-slate-50 p-3">
<span className={`mt-0.5 rounded-lg p-2 ${TYPE_META[pageSource.type].bg} ${TYPE_META[pageSource.type].color}`}><Icon name={TYPE_META[pageSource.type].icon} /></span>
<div className="min-w-0 flex-1"><p className="text-[10px] font-medium uppercase tracking-wider text-slate-500">{pageSource.reason}</p><p className="mt-1 line-clamp-2 break-words text-xs font-medium leading-relaxed text-slate-800">{page?.title || pageSource.identifier}</p><button className="mt-1 text-[11px] font-medium text-blue-600 hover:underline disabled:opacity-50" disabled={busy} onClick={() => { editIdentifier(pageSource.identifier); setMode('auto') }}>Use this page</button></div>
<div className="min-w-0 flex-1"><p className="text-[10px] font-medium uppercase tracking-wider text-slate-500">{pageSource.reason}</p><p className="mt-1 line-clamp-2 break-words text-xs font-medium leading-relaxed text-slate-800">{page?.title || pageSource.identifier}</p><button className="mt-1 text-[11px] font-medium text-blue-600 hover:underline disabled:opacity-50" disabled={busy} onClick={() => { editIdentifier(pageSource.identifier); setMode('auto') }}>{pageSource.buttonLabel || 'Use this page'}</button></div>
</div>}
<form onSubmit={save} className="space-y-4" aria-label="Save to Inbox">
<div>
Expand Down
Loading
Loading