Repository navigation
feat(search): add opt-in Local-First Search - #19
Conversation
Local-first search will pre-select a tab, bookmark or history entry when the query starts a host label or path segment of its URL (e.g. "pulls" for github.com/pulls/). The rule lives in an import-free module so it can be unit-tested with Node's built-in test runner. - the TLD is ignored so queries like "com" or "dev" don't match every site - query string and fragment are ignored so past Google searches for the same words don't count as strong matches
applyLocalFirst marks the strongest local match as the Top Hit and engine suggestions as Suggestions, so the palette can show local results before remote ones without changing how rows are activated. - precedence is open tab, bookmark, history, so Enter reuses an open tab instead of opening a duplicate - nothing is promoted over bangs, URLs to open or actions, which already outrank the plain web search today - placement uses a _section flag rather than new result types, so results without it render exactly as before
When enabled, palette and new tab search results are passed through applyLocalFirst so a strong local match can become the Top Hit and engine suggestions can move below tabs, bookmarks and history. - off by default, so existing users see no change - engine suggestions are tagged at creation, since they share the 'search' type with the explicit "Search ... for" row - applied after the URL dedupe so the Top Hit is always a row that is actually sent to the palette
The tests/ folder added for searchRanking is dev-only and is not loaded by the extension.
The new tab page and the in-page palette now honour the _section tag set by Local-First Search: the Top Hit renders first (so Enter opens it) and engine suggestions render last under their own header. Results without _section are grouped by type exactly as before, so nothing changes while the setting is off.
Manual testing showed "corr" promoting a recent corriere.it article instead of the homepage, because history comes back most recent first and the first strong match won. Within the winning type the shortest matching URL now wins; type precedence (tab, bookmark, history) is unchanged, so an open tab still beats a shorter history entry.
In the in-page palette the tab you are on can strongly match the query (e.g. "pulls" on github.com/pulls/) and become the Top Hit, so Enter switches to the same tab and nothing happens. The new tab page's own tab had the same problem. The tab the search comes from is no longer a Top Hit candidate; it is still listed under Open Tabs.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
PS I noticed CodeRabbit's security notes point at two small hardening gaps in this PR. Neither is a vulnerability on its own, and both are cheap to close. Here's what I'd do. 1. The Top Hit doesn't restrict URL schemes A bookmarklet such as Fix: only 2. The 500 ms search cache ignores which tab is searching
Fix: include the sender tab and the setting value in the cache key. Both are small, test-first changes. Would you like them in this PR, or in a follow-up after this one is merged? |
|
Hello @CubeSeven! Thanks for building Tabs++ 🙏 , I use it daily and this PR adds the thing I missed most (issue #18). TL;DR: opt-in "Local-First Search" toggle (off by default), tests included, CodeRabbit is green, and it follows AGENTS.md. I know you may be busy, so no rush. To make the review easy:
Could you let me know how you'd like contributions to be reviewed (for example, any timing or process I should follow)? And if the feature doesn't fit the direction of the project, I'd also appreciate knowing, so I don't keep it hanging. Thanks! |
|
Hi Pietro — sorry for the silence, work buried me and this sat in the queue far longer than it should have. Thanks for the PR and for the write-up, the test plan and the tests; that is a better contribution than most and I appreciate you using the extension daily and fixing the thing that annoyed you most. I went through the diff properly, and I ran your tests myself: Verdict: I want this in. A few answers before you push the last changes.
const parsed = new URL(url);
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return false;I checked it: Three small notes, none blocking:
On your "Enter before results arrive" limit and the caps (tabs 5 / history 10): documented, fine, no change wanted. On process, since you asked: small single-feature PRs like this are exactly what I want, tests are welcome (CI will run them from here), and |
A bookmarklet such as javascript:document.title strong-matched "doc", so it could become the pre-selected Top Hit and Enter would run it on the current page. chrome:// and file:// URLs matched as well. Asked for in the review of CubeSeven#19.
Only a leading "www." was stripped, so hosts such as www2.example.com kept a "www2" label and the query "www" strong-matched them. Noted in the review of CubeSeven#19.
Dropping only the last host label leaves "co" in docs.google.co.uk and "com" in bbc.com.au. Say why that is acceptable, as asked in the review of CubeSeven#19, and note that 3-letter labels still match their exact query.
The maintainer asked for tests/ to run in CI as part of CubeSeven#19. Pin Node 24 (the current LTS). setup-node@v7 runs on Node 24, so it does not add another Node 20 deprecation warning like the one checkout@v4 gets.
|
Thanks @CubeSeven, no worries at all about the wait, and thanks for the careful review! Everything you asked for is in (4 new commits), plus the Verified: 20/20 tests on Node 24 and 26, the CI steps run locally (plus Left out on purpose
Could you approve the workflow runs and take another look when you have a moment? Thanks! |
Summary
Adds an opt-in Local-First Search toggle (popup, Tools, off by default). When it's on, the new tab page and the in-page palette list tabs, bookmarks and history before web suggestions, and a strong URL match becomes a pre-selected Top Hit.
pullswith the toggle on:How it works: when the setting is on,
handleSearchItemspasses the deduped results toapplyLocalFirst(newservices/searchRanking.js, no imports, so it runs undernode --test). It tags rows with_section: 'tophit' | 'suggestion'instead of adding result types, so Enter and click handling are untouched. The renderers inntp.jsandcontent.jsgroup by_sectionfirst, then by type.Changes
_suggestionflag), and nothing is migrated, so it's easy to revert.http(s)URL whose domain label or path segment starts with the query (3+ characters; scheme,www./www2., TLD, query string and fragment are ignored). Tabs beat bookmarks, bookmarks beat history, the shortest URL wins within a type, and the tab you're searching from is skipped.>mode: today's first row stays first.docs/docs.html, andCONTRIBUTING.mdexplains how to run the tests.tests/is excluded from the store zip.pr-checks.ymlrunsnode --teston Node 24 (actions/setup-node@v7).Test Plan
node --testfrom the repo root: 20/20 on Node 24 and 26 (match rule incl.http(s)only andwww2., precedence and shortest URL, current tab skipped, no-promotion cases, input not mutated)pr-checks.ymlsteps run locally: manifest,node --checkon all JS, noconsole.log/debugger,git diff --check;actionlinton the workflowpullswithgithub.com/pulls/inboxopen (NTP and palette): Top Hit = that tab; Enter switches to itpullson that inbox tab itself (palette): Top Hit = the/pulls/authoredbookmark; the tab stays under Open Tabscorr(NTP): Top Hit = thecorriere.it/homepage, not a recent article; Enter opens itweatherandpu(NTP): no Top Hit!gh pulls,github.com,2+2,16px(NTP): the bang, "Go to" or converter row stays firstpulls(NTP and palette): same as beforepulls(NTP) still gives the inbox tab as Top HitBefore / after (new tab page,
pulls):Related
Closes #18
Not in this PR (happy to follow up):
bbcproduce Color Converter rows, which block the Top Hit (kept on purpose, per review). Tabs (5) and history (10) are capped before ranking.handleSearchItemsis keyed on the query only, so it ignores the searching tab and the setting. It only shows when the same query comes from two tabs within half a second.SECTION_ORDER/SECTION_LABELSare duplicated inntp.jsandcontent.js, and search rows say "Google Search" whatever the engine.Summary by CodeRabbit