Browser extension
The extension in extension/ brings pages, PDFs and references from the student's browser into Scholar Lens. It exists because the student's browser can read what the server can't: course pages and papers behind a university login. This page explains its parts and the server side it talks to. For using it, see the user guide.
Principles
- The student's session stays in the browser. Pages behind a login are read in the student's own tab. Scholar Lens never sees their university credentials.
- Nothing is fetched unless ticked. References are listed and looked up, but only the ones the student ticks are brought in. Papers behind a login are fetched one at a time, never in bulk.
- Private by default. Everything saved goes to the student's own Library and the chosen Space. Nothing reaches the shared Library.
- Least permission.
activeTabandscriptingfor the tab the student clicked on,contextMenus,storage, and optional host access for the Scholar Lens address and for a publisher only when asked. Never all sites.
Parts
Manifest V3, TypeScript, built with Vite. No UI framework.
| File | What it does |
|---|---|
popup.ts, popup.html | The popup: connect, the tab's title and kind, Space picker, save, Found on this page, the login-fetch list |
page.ts | Functions injected into the tab with chrome.scripting.executeScript: snapshot the rendered HTML, fetch the PDF the tab shows, scan links and references. Each is self-contained, because it is serialised. |
found.ts | The Found on this page list: files, web pages and references, each with a tick box, and bringing the ticked ones in. Found by page.ts: linked PDFs, slides, Moodle resources; links to other sites; DOI and arXiv links; citation_reference tags; the list under a References heading |
background.ts | The service worker: fetches papers that need the student's login, and handles the right-click highlight |
jobs.ts | The login-fetch queue, shared by the popup and the worker, kept in chrome.storage.session |
client.ts | Calls to the API with the personal access token |
settings.ts | The address, token and last Space, in chrome.storage.local |
Saving a page
- The popup asks the tab for its rendered HTML (
outerHTML), or fetches the PDF inside the tab with the student's cookies. - It posts it to
POST /api/capturewith the address, title and Space. - The server stores a page as a Library item of kind
page, indexed with trafilatura's article text (or all the text when the article is under 400 characters, as on course platforms). A PDF becomes a normal file item with its source address. - The server reads citation metadata from the page (see Ingestion).
- The same address, or the same PDF content, returns the earlier item with
duplicate: trueand adds it to the Space. - A saved page keeps its links to other sites as Markdown links in its text (
html_to_markdown(..., outside_links=True)); links within the course site become plain text. The quote check reads the text with the addresses unwrapped.
Items linked to their page
The popup saves the page first and sends its id as from_document_id with every ticked reference, file, web page and video (also to the background worker for papers fetched with the student's login). capture.link_from stores a document_links row (page, item, kind). spaces.retrieval_sources adds the ready items linked from every searched source, so a chat narrowed to the page still searches its references; an item is also a Space source of its own. documents_out returns linked_from (the pages) and links (on a page, the count). Replacing an item as a duplicate moves its links.
Reading lists without a References heading: a p or li in the page's main content that links out and reads like a citation (a year, and author initials, "et al.", a quoted title or a venue word) is a reference. A DOI in its link (doi.org, /doi/10.…, /article/10.…, ?id=10.…) gives a key; otherwise its text, without "link to paper", is looked up. Its links are not listed again as web pages.
Web pages
findOnPage lists links to other sites from the page's main content (#region-main, [role=main], main or article), skipping menus, header, footer, the page's own site, and sharing or sign-in hosts. Ticked ones go to POST /api/capture/link, which queues a web import (the URL importer's SSRF guard applies) or returns the student's earlier item for that address. A vague label ("here", "read more") leaves the URL as the title, so the importer uses the page's own.
References
- The popup sends the found references with the article's title and abstract and the Space to
POST /api/capture/resolve. app/ingestion/reference_finder.pyidentifies each one (DOI, arXiv id, or text) and looks it up: OpenAlex first, in parallel; Crossref as a fallback, one request at a time because its public pool allows only one; arXiv with spacing. A text reference matches only when the found title is in the entry and the years agree within one.- Each gets a status: open access, needs your login, in your Library, or reference only.
- The server ranks them by embedding similarity to the article and the Space's title and instructions, and returns them most related first.
POST /api/capture/explainwrites one or two lines about each of the top 10, from its title and abstract only, with the local model.POST /api/capture/referencesbrings in the ticked ones: an open-access paper as a normal DOI or arXiv import, the rest as reference-only items (statusreference, no text, no chunks). A publisher that refuses the server's download leaves a reference-only item too.
Papers behind a login
The popup closes as soon as the student clicks into another tab, so the background worker does this work:
- Ask for host access to the publisher (its site and sister domains, for example
elsevier.comandsciencedirect.com). - Open the paper's landing page (from
/api/capture/resolve, where the DOI points) in a background tab. - Find the PDF:
citation_pdf_url, a PDF or download link, or an embedded viewer frame. - Fetch it inside the tab with the student's cookies. If that gives no PDF, try the worker's own request, then load the PDF in the tab.
- A real PDF (starting with
%PDF) goes to/api/capturewith the reference's details. It fills the reference-only item in place, keeping its metadata and Spaces. - Otherwise the job waits as sign in needed. The toolbar badge counts waiting papers. The student signs in on the tab and presses Continue.
Highlights
The right-click item posts the selected text to POST /api/capture/highlight. The server adds a note on the student's item for that address. If the page is not saved yet (404 not_saved), the worker saves it into the last Space first and tries again.
The token
The extension authenticates with a personal access token, limited to /api/me, /api/spaces and /api/capture* (see Security and access). A revoked token sends the popup back to the connect screen.
Build and check
From extension/:
bash
npm cibash
npm run buildbash
npm run lintThe build writes extension/dist, which is loaded unpacked in Chrome or Edge. CI runs lint, types and build for pull requests into main.