From 07c398101726ca556e8a0493bb8b43755b2f729c Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sat, 10 Oct 2026 20:04:44 +0000 Subject: [PATCH 1/2] feat(clipper): Lens web clipper browser extension, Chrome first A MV3 extension in extensions/browser: clip the page (Readability), the selection or a picked element to Markdown with MarkDownload-style templates, and send it to Lens through a namespace's import webhook. Shared core for the Firefox, Edge and Safari targets; CI builds a zip per target and attaches them to releases. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_018uA6PhZXrmpgsbfDh2W23u --- .github/workflows/browser-extension.yml | 68 ++ .github/workflows/release.yml | 2 +- docs/web-clipper.md | 105 ++ extensions/browser/.gitignore | 2 + extensions/browser/README.md | 13 + extensions/browser/package-lock.json | 1070 +++++++++++++++++++++ extensions/browser/package.json | 22 + extensions/browser/scripts/build.mjs | 68 ++ extensions/browser/src/background.js | 177 ++++ extensions/browser/src/content.js | 30 + extensions/browser/src/core/clip.js | 72 ++ extensions/browser/src/core/lens.js | 100 ++ extensions/browser/src/core/markdown.js | 126 +++ extensions/browser/src/core/metadata.js | 97 ++ extensions/browser/src/core/picker.js | 79 ++ extensions/browser/src/core/settings.js | 83 ++ extensions/browser/src/core/template.js | 141 +++ extensions/browser/src/icons/icon-128.png | Bin 0 -> 7301 bytes extensions/browser/src/icons/icon-16.png | Bin 0 -> 1168 bytes extensions/browser/src/icons/icon-32.png | Bin 0 -> 2004 bytes extensions/browser/src/icons/icon-48.png | Bin 0 -> 2907 bytes extensions/browser/src/manifest.json | 24 + extensions/browser/src/ui/options.html | 94 ++ extensions/browser/src/ui/options.js | 177 ++++ extensions/browser/src/ui/popup.html | 40 + extensions/browser/src/ui/popup.js | 114 +++ extensions/browser/src/ui/style.css | 64 ++ extensions/browser/targets/chrome.json | 3 + extensions/browser/test/clip.test.js | 82 ++ extensions/browser/test/fixtures.js | 33 + extensions/browser/test/lens.test.js | 63 ++ extensions/browser/test/template.test.js | 34 + mkdocs.yml | 1 + 33 files changed, 2983 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/browser-extension.yml create mode 100644 docs/web-clipper.md create mode 100644 extensions/browser/.gitignore create mode 100644 extensions/browser/README.md create mode 100644 extensions/browser/package-lock.json create mode 100644 extensions/browser/package.json create mode 100644 extensions/browser/scripts/build.mjs create mode 100644 extensions/browser/src/background.js create mode 100644 extensions/browser/src/content.js create mode 100644 extensions/browser/src/core/clip.js create mode 100644 extensions/browser/src/core/lens.js create mode 100644 extensions/browser/src/core/markdown.js create mode 100644 extensions/browser/src/core/metadata.js create mode 100644 extensions/browser/src/core/picker.js create mode 100644 extensions/browser/src/core/settings.js create mode 100644 extensions/browser/src/core/template.js create mode 100644 extensions/browser/src/icons/icon-128.png create mode 100644 extensions/browser/src/icons/icon-16.png create mode 100644 extensions/browser/src/icons/icon-32.png create mode 100644 extensions/browser/src/icons/icon-48.png create mode 100644 extensions/browser/src/manifest.json create mode 100644 extensions/browser/src/ui/options.html create mode 100644 extensions/browser/src/ui/options.js create mode 100644 extensions/browser/src/ui/popup.html create mode 100644 extensions/browser/src/ui/popup.js create mode 100644 extensions/browser/src/ui/style.css create mode 100644 extensions/browser/targets/chrome.json create mode 100644 extensions/browser/test/clip.test.js create mode 100644 extensions/browser/test/fixtures.js create mode 100644 extensions/browser/test/lens.test.js create mode 100644 extensions/browser/test/template.test.js diff --git a/.github/workflows/browser-extension.yml b/.github/workflows/browser-extension.yml new file mode 100644 index 000000000..7babafccb --- /dev/null +++ b/.github/workflows/browser-extension.yml @@ -0,0 +1,68 @@ +name: Browser extension + +# The Lens web clipper (extensions/browser): tested and built for each browser in extensions/browser/targets/, and +# kept with the run as lens-clipper-.zip (unzip and "Load unpacked", or hand to the browser's store). A release +# gets the zips attached: through the release event, or workflow_dispatch with `tag` (the Release workflow starts it). +on: + push: + branches: [main] + paths: + - extensions/browser/** + - .github/workflows/browser-extension.yml + pull_request: + paths: + - extensions/browser/** + - .github/workflows/browser-extension.yml + release: + types: [published] + workflow_dispatch: + inputs: + tag: + description: "Release tag to attach the extension to (the Release workflow passes it); blank: build this ref" + default: "" + +permissions: + contents: read + +jobs: + build: + name: Test and build the web clipper + runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }} + permissions: + contents: write # to attach the zips to a release + defaults: + run: + working-directory: ./extensions/browser + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.tag || github.ref }} + - uses: actions/setup-node@v7 + with: + node-version: "22" + cache: npm + cache-dependency-path: extensions/browser/package-lock.json + - run: npm ci + - run: npm test + - name: Build every target + env: + EXT_VERSION: ${{ github.event.release.tag_name || inputs.tag }} + run: npm run check + - name: Zip them + run: | + mkdir -p ../../dist/extension + for d in dist/*/; do + t=$(basename "$d") + (cd "$d" && zip -qr "../../../../dist/extension/lens-clipper-$t.zip" .) + done + ls -l ../../dist/extension + - uses: actions/upload-artifact@v7 + with: + name: lens-clipper + path: dist/extension/*.zip + - name: Attach to the release + if: github.event_name == 'release' || inputs.tag != '' + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.event.release.tag_name || inputs.tag }} + run: gh release upload "$TAG" ../../dist/extension/*.zip --clobber --repo "${{ github.repository }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 91c3ef9b7..df3570a6b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -152,7 +152,7 @@ jobs: # RELEASE_TOKEN's release fires `release: published` in them already if: env.EXISTING != 'true' && env.HAS_RELEASE_TOKEN != 'true' run: | - for workflow in cloudron.yml qnap.yml synology.yml launchers.yml; do + for workflow in cloudron.yml qnap.yml synology.yml launchers.yml browser-extension.yml; do if [ ! -f ".github/workflows/$workflow" ]; then echo "$workflow isn't in $TAG; skipped" elif gh workflow run "$workflow" --ref "$TAG" -f tag="$TAG"; then diff --git a/docs/web-clipper.md b/docs/web-clipper.md new file mode 100644 index 000000000..f1ea50282 --- /dev/null +++ b/docs/web-clipper.md @@ -0,0 +1,105 @@ +# Web clipper + +**Status: built (Chrome).** Firefox, Edge and Safari builds come from the same code; each gets a target in +`extensions/browser/targets/`. + +The Lens web clipper is a browser extension that turns what you're reading into Markdown and sends it to your Lens, +where it's imported like pasted text and runs through the namespace's pipeline. It works like MarkDownload: you +choose what to clip, look over the Markdown, and send it, copy it or download it as a `.md` file. + +## What it clips + +- **The page**: the article, through Mozilla's Readability (menus, ads and footers left out; turn that off in the + options to keep the whole page), with its metadata: title, author, site, publish date, lead image, keywords and + language, from the page's meta tags, Open Graph and JSON-LD. +- **The selection**: what you've selected, keeping the list, table, quote or code block it's in. +- **A part you pick**: hover to outline an element, ↑ to widen to its parent, ↓ to narrow again, + click or Enter to take it, Esc to stop. +- **A link or an image** from the right-click menu: a link is sent for Lens to capture itself (a PDF as it is, a page + printed by Chromium on the full image); an image is sent as a file. + +Relative links and images become absolute, lazy-loaded images are loaded, code blocks keep their language, and +tables, strikethrough and task lists become GitHub-style Markdown. + +## Setting it up + +1. In Lens, open a namespace's admin page and make an **import webhook** (see [the API](api.md), Import webhooks). + Copy its token: it's shown once. +2. In the clipper's options, enter your Lens address and the token and press **Add and check**. The browser asks to + let the clipper talk to that address; the clipper then checks the token without importing anything. + +Add one per namespace you clip into, and pick between them in the popup. The tokens stay on this device; every other +setting syncs through your browser account. Plain `http://` addresses are only accepted on this computer or the local +network. + +## Ways to clip + +| | | +| --- | --- | +| Toolbar button, or Alt+Shift+L | the popup: clips the selection if there is one, else the page, for you to look over and send | +| Right-click, or Alt+Shift+P / S | clip the page / the selection and send it straight away (a ✓ on the button when it's in) | +| Right-click **Pick part of the page**, or Alt+Shift+K | the picker, then send | + +With **Right-click and shortcut clips open the popup** on, those open the popup to look over first instead. + +## Templates + +What's sent is the template with the clip's variables filled in. The default puts the metadata in YAML front matter +and the content under the title: + +```markdown +--- +title: {title|yaml} +source: {url} +author: {byline|yaml} +site: {siteName|yaml} +published: {published:YYYY-MM-DD} +clipped: {date:YYYY-MM-DDTHH:mm:ssZ} +image: {image} +tags: {tags|list} +--- + +# {title} + +{content} +``` + +A front matter line whose value comes out empty is left out. Selections and picked parts can have a template of their +own; the title has one too (`{title}` by default). + +Variables: `title`, `url`, `domain`, `origin`, `siteName`, `byline`, `excerpt`, `published`, `modified`, `date` (now), +`keywords`, `tags` (yours, from the options), `image`, `lang`, `clipType` (`page`, `selection` or `element`) and +`content`. + +- Dates take a format after a colon: `{date:YYYY-MM-DD HH:mm}` (`YYYY YY MM M DD D HH H mm ss Z`). +- Lists take a separator after a colon: `{keywords:, }`. +- Filters follow a bar and chain: `{title|kebab}`, `{title|lower|trim}`. There are `lower`, `upper`, `trim`, `kebab`, + `snake`, `camel`, `pascal`, `title`, `filename`, `yaml`, `list`, `hashtags`, `json` and `first`. +- `{{` and `}}` are literal braces. + +## Markdown and clipping options + +Heading style, bullet marker, fenced or indented code and its fence, emphasis and strong markers, inline or reference +links, links kept or reduced to their text, images kept, reduced to their alt text or dropped, and GitHub tables on or +off. + +**Also send the clip's images as files** pushes up to 19 of the content's images along with the Markdown; each becomes +a resource in Lens. The browser asks once to let the clipper read images from any site. **Also ask Lens to capture the +page itself** sends the address too, for a PDF snapshot next to the Markdown (needs Chromium on your Lens). + +## Building it + +```sh +cd extensions/browser +npm ci +npm test # templates, metadata, Markdown, sending (jsdom) +npm run build # dist// for every target; --target chrome for one +``` + +Load `dist/chrome` with **Load unpacked** on `chrome://extensions` (Developer mode on). The Browser extension workflow +builds every target on each pull request that changes the clipper and keeps `lens-clipper-.zip` with the run; +a release gets them attached. + +A target is `extensions/browser/targets/.json`, merged over `src/manifest.json` (a `null` removes a key), so a +browser that needs something different (Firefox's `browser_specific_settings` and background `scripts`, say) adds only +that. The code reaches the extension API as `globalThis.browser ?? globalThis.chrome`. diff --git a/extensions/browser/.gitignore b/extensions/browser/.gitignore new file mode 100644 index 000000000..b94707787 --- /dev/null +++ b/extensions/browser/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +dist/ diff --git a/extensions/browser/README.md b/extensions/browser/README.md new file mode 100644 index 000000000..52f4c952e --- /dev/null +++ b/extensions/browser/README.md @@ -0,0 +1,13 @@ +# Lens web clipper + +A browser extension that clips pages, selections or any part of a page into Lens as Markdown, with the page's +metadata and images, through a namespace's import webhook. See [docs/web-clipper.md](../../docs/web-clipper.md). + +```sh +npm ci && npm test && npm run build # then Load unpacked: dist/chrome +``` + +- `src/core/`: the shared code every browser uses: `clip.js` (page, selection, element), `metadata.js`, + `markdown.js` (Turndown), `template.js`, `picker.js`, `lens.js` (pushing to Lens), `settings.js` +- `src/background.js`, `src/content.js`, `src/ui/`: the extension around it +- `targets/.json`: what each browser's manifest changes from `src/manifest.json` diff --git a/extensions/browser/package-lock.json b/extensions/browser/package-lock.json new file mode 100644 index 000000000..218aefcc1 --- /dev/null +++ b/extensions/browser/package-lock.json @@ -0,0 +1,1070 @@ +{ + "name": "lens-web-clipper", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "lens-web-clipper", + "version": "0.1.0", + "license": "MIT", + "dependencies": { + "@mozilla/readability": "0.6.0", + "turndown": "7.2.4", + "turndown-plugin-gfm": "1.0.2" + }, + "devDependencies": { + "esbuild": "0.28.2", + "jsdom": "26.1.0" + } + }, + "node_modules/@asamuzakjp/css-color": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-3.2.0.tgz", + "integrity": "sha512-K1A6z8tS3XsmCMM86xoWdn7Fkdn9m6RSVtocUrJYIwZnFVkng/PvkEoWtOWmP+Scc6saYWHWZYbndEEXxl24jw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@csstools/css-calc": "^2.1.3", + "@csstools/css-color-parser": "^3.0.9", + "@csstools/css-parser-algorithms": "^3.0.4", + "@csstools/css-tokenizer": "^3.0.3", + "lru-cache": "^10.4.3" + } + }, + "node_modules/@csstools/color-helpers": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-5.1.0.tgz", + "integrity": "sha512-S11EXWJyy0Mz5SYvRmY8nJYTFFd1LCNV+7cXyAgQtOOuzb4EsgfqDufL+9esx72/eLhsRdGZwaldu/h+E4t4BA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT-0", + "engines": { + "node": ">=18" + } + }, + "node_modules/@csstools/css-calc": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@csstools/css-calc/-/css-calc-2.1.4.tgz", + "integrity": "sha512-3N8oaj+0juUw/1H3YwmDDJXCgTB1gKU6Hc/bB502u9zR0q2vd786XJH9QfrKIEgFlZmhZiq6epXl4rHqhzsIgQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^3.0.5", + "@csstools/css-tokenizer": "^3.0.4" + } + }, + "node_modules/@csstools/css-color-parser": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@csstools/css-color-parser/-/css-color-parser-3.1.0.tgz", + "integrity": "sha512-nbtKwh3a6xNVIp/VRuXV64yTKnb1IjTAEEh3irzS+HkKjAOYLTGNb9pmVNntZ8iVBHcWDA2Dof0QtPgFI1BaTA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "dependencies": { + "@csstools/color-helpers": "^5.1.0", + "@csstools/css-calc": "^2.1.4" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^3.0.5", + "@csstools/css-tokenizer": "^3.0.4" + } + }, + "node_modules/@csstools/css-parser-algorithms": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-3.0.5.tgz", + "integrity": "sha512-DaDeUkXZKjdGhgYaHNJTV9pV7Y9B3b644jCLs9Upc3VeNGg6LWARAT6O+Q+/COo+2gg/bM5rhpMAtf70WqfBdQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-tokenizer": "^3.0.4" + } + }, + "node_modules/@csstools/css-tokenizer": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-3.0.4.tgz", + "integrity": "sha512-Vd/9EVDiu6PPJt9yAh6roZP6El1xHrdvIVGjyBsHR0RYwNHgL7FJPyIIW4fANJNG6FtyZfvlRPpFI4ZM/lubvw==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz", + "integrity": "sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.2.tgz", + "integrity": "sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.2.tgz", + "integrity": "sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.2.tgz", + "integrity": "sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.2.tgz", + "integrity": "sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.2.tgz", + "integrity": "sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.2.tgz", + "integrity": "sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.2.tgz", + "integrity": "sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.2.tgz", + "integrity": "sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.2.tgz", + "integrity": "sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.2.tgz", + "integrity": "sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.2.tgz", + "integrity": "sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.2.tgz", + "integrity": "sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.2.tgz", + "integrity": "sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.2.tgz", + "integrity": "sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.2.tgz", + "integrity": "sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.2.tgz", + "integrity": "sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.2.tgz", + "integrity": "sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.2.tgz", + "integrity": "sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.2.tgz", + "integrity": "sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.2.tgz", + "integrity": "sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.2.tgz", + "integrity": "sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.2.tgz", + "integrity": "sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.2.tgz", + "integrity": "sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.2.tgz", + "integrity": "sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.2.tgz", + "integrity": "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@mixmark-io/domino": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@mixmark-io/domino/-/domino-2.2.0.tgz", + "integrity": "sha512-Y28PR25bHXUg88kCV7nivXrP2Nj2RueZ3/l/jdx6J9f8J4nsEGcgX0Qe6lt7Pa+J79+kPiJU3LguR6O/6zrLOw==", + "license": "BSD-2-Clause" + }, + "node_modules/@mozilla/readability": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@mozilla/readability/-/readability-0.6.0.tgz", + "integrity": "sha512-juG5VWh4qAivzTAeMzvY9xs9HY5rAcr2E4I7tiSSCokRFi7XIZCAu92ZkSTsIj1OPceCifL3cpfteP3pDT9/QQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, + "node_modules/cssstyle": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-4.6.0.tgz", + "integrity": "sha512-2z+rWdzbbSZv6/rhtvzvqeZQHrBaqgogqt85sqFNbabZOuFbCVFb8kPeEtZjiKkbrm395irpNKiYeFeLiQnFPg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@asamuzakjp/css-color": "^3.2.0", + "rrweb-cssom": "^0.8.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/data-urls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", + "integrity": "sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/decimal.js": { + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.6.0.tgz", + "integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==", + "dev": true, + "license": "MIT" + }, + "node_modules/entities": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-6.0.1.tgz", + "integrity": "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/esbuild": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz", + "integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.2", + "@esbuild/android-arm": "0.28.2", + "@esbuild/android-arm64": "0.28.2", + "@esbuild/android-x64": "0.28.2", + "@esbuild/darwin-arm64": "0.28.2", + "@esbuild/darwin-x64": "0.28.2", + "@esbuild/freebsd-arm64": "0.28.2", + "@esbuild/freebsd-x64": "0.28.2", + "@esbuild/linux-arm": "0.28.2", + "@esbuild/linux-arm64": "0.28.2", + "@esbuild/linux-ia32": "0.28.2", + "@esbuild/linux-loong64": "0.28.2", + "@esbuild/linux-mips64el": "0.28.2", + "@esbuild/linux-ppc64": "0.28.2", + "@esbuild/linux-riscv64": "0.28.2", + "@esbuild/linux-s390x": "0.28.2", + "@esbuild/linux-x64": "0.28.2", + "@esbuild/netbsd-arm64": "0.28.2", + "@esbuild/netbsd-x64": "0.28.2", + "@esbuild/openbsd-arm64": "0.28.2", + "@esbuild/openbsd-x64": "0.28.2", + "@esbuild/openharmony-arm64": "0.28.2", + "@esbuild/sunos-x64": "0.28.2", + "@esbuild/win32-arm64": "0.28.2", + "@esbuild/win32-ia32": "0.28.2", + "@esbuild/win32-x64": "0.28.2" + } + }, + "node_modules/html-encoding-sniffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", + "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-encoding": "^3.1.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/http-proxy-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", + "integrity": "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.0", + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/https-proxy-agent": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", + "dev": true, + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/jsdom": { + "version": "26.1.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-26.1.0.tgz", + "integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==", + "dev": true, + "license": "MIT", + "dependencies": { + "cssstyle": "^4.2.1", + "data-urls": "^5.0.0", + "decimal.js": "^10.5.0", + "html-encoding-sniffer": "^4.0.0", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.6", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.16", + "parse5": "^7.2.1", + "rrweb-cssom": "^0.8.0", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^5.1.1", + "w3c-xmlserializer": "^5.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^3.1.1", + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.1.1", + "ws": "^8.18.0", + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "canvas": "^3.0.0" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } + } + }, + "node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/nwsapi": { + "version": "2.2.28", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.28.tgz", + "integrity": "sha512-IlVB7OS7qrOsVYlpnFIkETjMwT9jwvmocJmmM+GZU/PAB3uGi9Ezd7vcWhWBUnSc0ya4ppmQITOyP1ez9gg8cg==", + "dev": true, + "license": "MIT" + }, + "node_modules/parse5": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.3.0.tgz", + "integrity": "sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "entities": "^6.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/rrweb-cssom": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.8.0.tgz", + "integrity": "sha512-guoltQEx+9aMf2gDZ0s62EcV8lsXR+0w8915TC3ITdn2YueuNjdAYh/levpU9nFaoChh9RUS5ZdQMrKfVEN9tw==", + "dev": true, + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "dev": true, + "license": "MIT" + }, + "node_modules/saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dev": true, + "license": "ISC", + "dependencies": { + "xmlchars": "^2.2.0" + }, + "engines": { + "node": ">=v12.22.7" + } + }, + "node_modules/symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", + "dev": true, + "license": "MIT" + }, + "node_modules/tldts": { + "version": "6.1.86", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.86.tgz", + "integrity": "sha512-WMi/OQ2axVTf/ykqCQgXiIct+mSQDFdH2fkwhPwgEwvJ1kSzZRiinb0zF2Xb8u4+OqPChmyI6MEu4EezNJz+FQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "tldts-core": "^6.1.86" + }, + "bin": { + "tldts": "bin/cli.js" + } + }, + "node_modules/tldts-core": { + "version": "6.1.86", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.86.tgz", + "integrity": "sha512-Je6p7pkk+KMzMv2XXKmAE3McmolOQFdxkKw0R8EYNr7sELW46JqnNeTX8ybPiQgvg1ymCoF8LXs5fzFaZvJPTA==", + "dev": true, + "license": "MIT" + }, + "node_modules/tough-cookie": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.2.tgz", + "integrity": "sha512-FVDYdxtnj0G6Qm/DhNPSb8Ju59ULcup3tuJxkFb5K8Bv2pUXILbf0xZWU8PX8Ov19OXljbUyveOFwRMwkXzO+A==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "tldts": "^6.1.32" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/turndown": { + "version": "7.2.4", + "resolved": "https://registry.npmjs.org/turndown/-/turndown-7.2.4.tgz", + "integrity": "sha512-I8yFsfRzmzK0WV1pNNOA4A7y4RDfFxPRxb3t+e3ui14qSGOxGtiSP6GjeX+Y6CHb7HYaFj7ECUD7VE5kQMZWGQ==", + "license": "MIT", + "dependencies": { + "@mixmark-io/domino": "^2.2.0" + }, + "engines": { + "node": ">=18", + "npm": ">=9" + } + }, + "node_modules/turndown-plugin-gfm": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/turndown-plugin-gfm/-/turndown-plugin-gfm-1.0.2.tgz", + "integrity": "sha512-vwz9tfvF7XN/jE0dGoBei3FXWuvll78ohzCZQuOb+ZjWrs3a0XhQVomJEb2Qh4VHTPNRO4GPZh0V7VRbiWwkRg==", + "license": "MIT" + }, + "node_modules/w3c-xmlserializer": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "dev": true, + "license": "MIT", + "dependencies": { + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-encoding": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "deprecated": "Use @exodus/bytes instead for a more spec-conformant and faster implementation", + "dev": true, + "license": "MIT", + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-mimetype": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/ws": { + "version": "8.22.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.22.0.tgz", + "integrity": "sha512-Ydggc987+RO0AnWtZ/7Wq9FtNvcrL1b/RO0ud9mWjUPgDrsAAwQSF51sm2hm1XofbU/4jkpGEsLFsZZxU+1DOg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18" + } + }, + "node_modules/xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/extensions/browser/package.json b/extensions/browser/package.json new file mode 100644 index 000000000..d4cab0cff --- /dev/null +++ b/extensions/browser/package.json @@ -0,0 +1,22 @@ +{ + "name": "lens-web-clipper", + "version": "0.1.0", + "private": true, + "description": "Clip web pages, selections and picked elements into Lens as Markdown", + "license": "MIT", + "type": "module", + "scripts": { + "build": "node scripts/build.mjs", + "test": "node --test test/*.test.js", + "check": "node scripts/build.mjs --check" + }, + "dependencies": { + "@mozilla/readability": "0.6.0", + "turndown": "7.2.4", + "turndown-plugin-gfm": "1.0.2" + }, + "devDependencies": { + "esbuild": "0.28.2", + "jsdom": "26.1.0" + } +} diff --git a/extensions/browser/scripts/build.mjs b/extensions/browser/scripts/build.mjs new file mode 100644 index 000000000..4ef07ddd6 --- /dev/null +++ b/extensions/browser/scripts/build.mjs @@ -0,0 +1,68 @@ +// Builds the extension for each browser in targets/: dist// is what the browser loads (or the store gets). +// A target is targets/.json, merged over src/manifest.json (null removes a key). `--target chrome` builds one; +// `--check` builds and then checks every file the manifests name exists. +import { build } from "esbuild"; +import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); +const args = process.argv.slice(2); +const only = args.includes("--target") ? args[args.indexOf("--target") + 1] : null; +const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8")); +// a release builds with its own version (EXT_VERSION=v0.7.0); browsers take only dotted numbers +const version = (process.env.EXT_VERSION || pkg.version).replace(/^v/, "").replace(/[^0-9.].*$/, ""); + +function merge(base, over) { + const out = { ...base }; + for (const [k, v] of Object.entries(over)) { + if (v === null) delete out[k]; + else if (v && typeof v === "object" && !Array.isArray(v) && typeof out[k] === "object" && !Array.isArray(out[k])) out[k] = merge(out[k], v); + else out[k] = v; + } + return out; +} + +function referenced(m) { + const files = new Set([...Object.values(m.icons ?? {}), ...Object.values(m.action?.default_icon ?? {})]); + for (const f of [m.action?.default_popup, m.options_ui?.page, m.background?.service_worker, ...(m.background?.scripts ?? [])]) if (f) files.add(f); + return [...files]; +} + +const targets = readdirSync(join(root, "targets")) + .filter((f) => f.endsWith(".json")) + .map((f) => f.slice(0, -5)) + .filter((t) => !only || t === only); +if (!targets.length) throw new Error(`no target ${only} in targets/`); + +const base = JSON.parse(readFileSync(join(root, "src/manifest.json"), "utf8")); +for (const target of targets) { + const out = join(root, "dist", target); + rmSync(out, { recursive: true, force: true }); + mkdirSync(out, { recursive: true }); + await build({ + entryPoints: { + background: join(root, "src/background.js"), + content: join(root, "src/content.js"), + popup: join(root, "src/ui/popup.js"), + options: join(root, "src/ui/options.js"), + }, + outdir: out, + bundle: true, + format: "iife", + platform: "browser", + target: ["chrome116", "firefox115", "safari16"], + legalComments: "linked", + define: { "process.env.NODE_ENV": '"production"' }, + logLevel: "warning", + }); + for (const f of ["popup.html", "options.html", "style.css"]) cpSync(join(root, "src/ui", f), join(out, f)); + cpSync(join(root, "src/icons"), join(out, "icons"), { recursive: true }); + const manifest = merge({ ...base, version }, JSON.parse(readFileSync(join(root, "targets", `${target}.json`), "utf8"))); + writeFileSync(join(out, "manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`); + if (args.includes("--check")) { + const missing = referenced(manifest).filter((f) => !existsSync(join(out, f))); + if (missing.length) throw new Error(`${target}: the manifest names files the build lacks: ${missing.join(", ")}`); + } + console.log(`built dist/${target} (${manifest.name} ${manifest.version})`); +} diff --git a/extensions/browser/src/background.js b/extensions/browser/src/background.js new file mode 100644 index 000000000..aa8d22c42 --- /dev/null +++ b/extensions/browser/src/background.js @@ -0,0 +1,177 @@ +// The extension's background: context menus, shortcuts, and every push to Lens (so a send finishes even when the +// popup closes). +import { fetchImages, push } from "./core/lens.js"; +import * as settingsStore from "./core/settings.js"; + +const ext = globalThis.browser ?? globalThis.chrome; + +const MENU = [ + { id: "clip-page", title: "Clip this page to Lens", contexts: ["page"] }, + { id: "clip-selection", title: "Clip selection to Lens", contexts: ["selection"] }, + { id: "pick", title: "Pick part of the page to clip…", contexts: ["page", "selection"] }, + { id: "clip-link", title: "Send this link to Lens", contexts: ["link"] }, + { id: "clip-image", title: "Send this image to Lens", contexts: ["image"] }, +]; + +ext.runtime.onInstalled.addListener(async ({ reason }) => { + await ext.contextMenus.removeAll(); + for (const m of MENU) ext.contextMenus.create(m); + if (reason === "install") { + const s = await settingsStore.load(); + if (!s.destinations.length) ext.runtime.openOptionsPage(); + } +}); + +// ---------- running the clipper in a tab ---------- +async function inject(tabId) { + await ext.scripting.executeScript({ target: { tabId }, files: ["content.js"] }); +} + +async function clipTab(tabId, mode, tags) { + const settings = await settingsStore.load(); + await inject(tabId); + const [{ result }] = await ext.scripting.executeScript({ + target: { tabId }, + func: (args) => globalThis.__lensClipper.run(args), + args: [{ mode, settings, tags: tags ?? settings.tags }], + }); + if (!result?.ok) throw new Error(result?.error ?? "couldn't read this page"); + return result.clip; +} + +async function startPicker(tabId, intent) { + const settings = await settingsStore.load(); + await inject(tabId); + // not awaited: the pick comes back as a "picked" message + ext.scripting + .executeScript({ + target: { tabId }, + func: (args) => globalThis.__lensClipper.pick(args), + args: [{ settings, tags: settings.tags, intent }], + }) + .catch((e) => flag(tabId, false, e.message)); +} + +// ---------- sending ---------- +async function send(clip, destinationId) { + const settings = await settingsStore.load(); + const dest = settingsStore.destination(settings, destinationId); + if (!dest) throw new Error("Add your Lens in the clipper's options first"); + const token = await settingsStore.token(dest.id); + const images = settings.sendImages && clip.images?.length ? await fetchImages(clip.images, { max: settings.maxImages }) : []; + const answer = await push({ server: dest.server, token }, clip, { images, captureUrl: settings.captureOnServer }); + return { ...answer, server: dest.server, destination: dest.name }; +} + +async function sendLink(url, title) { + const settings = await settingsStore.load(); + const dest = settingsStore.destination(settings); + if (!dest) throw new Error("Add your Lens in the clipper's options first"); + const token = await settingsStore.token(dest.id); + const res = await fetch(`${dest.server}/api/v1/hooks/import`, { + method: "POST", + headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }, + body: JSON.stringify(title ? { url, title: title.slice(0, 200) } : { url }), + credentials: "omit", + }); + if (!res.ok) throw new Error((await res.json().catch(() => ({}))).detail ?? `Lens answered ${res.status}`); +} + +// ---------- telling the user ---------- +async function flag(tabId, ok, message) { + const opts = tabId ? { tabId } : {}; + await ext.action.setBadgeBackgroundColor({ ...opts, color: ok ? "#16a34a" : "#dc2626" }); + await ext.action.setBadgeText({ ...opts, text: ok ? "✓" : "!" }); + await ext.action.setTitle({ ...opts, title: ok ? `Lens: ${message}` : `Lens couldn't clip: ${message}` }); + if (ok) setTimeout(() => ext.action.setBadgeText({ ...opts, text: "" }), 4000); +} + +// a clip to look over first: kept for the popup, which opens if the browser lets it +async function stage(tabId, clip) { + await ext.storage.session.set({ pending: { clip, tabId, at: Date.now() } }); + try { + await ext.action.openPopup(); + } catch { + await ext.action.setBadgeBackgroundColor({ tabId, color: "#6d5dfc" }); + await ext.action.setBadgeText({ tabId, text: "1" }); + await ext.action.setTitle({ tabId, title: "Lens: your clip is ready, open the clipper to send it" }); + } +} + +async function quick(tab, mode) { + try { + const clip = await clipTab(tab.id, mode); + const settings = await settingsStore.load(); + if (settings.reviewQuickClips) return stage(tab.id, clip); + const answer = await send(clip); + await flag(tab.id, true, `sent to ${answer.namespace}`); + } catch (e) { + await flag(tab.id, false, e.message); + } +} + +ext.contextMenus.onClicked.addListener(async (info, tab) => { + try { + if (info.menuItemId === "clip-page") return quick(tab, "page"); + if (info.menuItemId === "clip-selection") return quick(tab, "selection"); + if (info.menuItemId === "pick") return startPicker(tab.id, "quick"); + if (info.menuItemId === "clip-link") { + await sendLink(info.linkUrl, info.selectionText); + return flag(tab.id, true, "link sent; Lens captures it"); + } + if (info.menuItemId === "clip-image") { + const settings = await settingsStore.load(); + const dest = settingsStore.destination(settings); + if (!dest) throw new Error("Add your Lens in the clipper's options first"); + const images = await fetchImages([info.srcUrl], { max: 1 }); + if (!images.length) throw new Error("couldn't download that image"); + const title = tab.title || info.srcUrl; + const markdown = `![](${info.srcUrl})\n\nFrom [${title}](${info.pageUrl})\n`; + await push({ server: dest.server, token: await settingsStore.token(dest.id) }, { title, markdown, url: info.pageUrl }, { images }); + return flag(tab.id, true, "image sent"); + } + } catch (e) { + await flag(tab?.id, false, e.message); + } +}); + +ext.commands.onCommand.addListener(async (command, tab) => { + tab ??= (await ext.tabs.query({ active: true, currentWindow: true }))[0]; + if (!tab) return; + if (command === "clip-page") return quick(tab, "page"); + if (command === "clip-selection") return quick(tab, "selection"); + if (command === "pick") return startPicker(tab.id, "quick"); +}); + +ext.runtime.onMessage.addListener((msg, sender, reply) => { + if (msg?.type === "picked") { + const tabId = sender.tab?.id; + (async () => { + if (!msg.ok) return flag(tabId, false, msg.error); + const settings = await settingsStore.load(); + if (msg.intent === "review" || settings.reviewQuickClips) return stage(tabId, msg.clip); + const answer = await send(msg.clip); + await flag(tabId, true, `sent to ${answer.namespace}`); + })().catch((e) => flag(tabId, false, e.message)); + return false; + } + if (msg?.type === "send") { + send(msg.clip, msg.destination).then( + (answer) => reply({ ok: true, answer }), + (e) => reply({ ok: false, error: e.message }), + ); + return true; // answers asynchronously + } + if (msg?.type === "clip") { + clipTab(msg.tabId, msg.mode, msg.tags).then( + (clip) => reply({ ok: true, clip }), + (e) => reply({ ok: false, error: e.message }), + ); + return true; + } + if (msg?.type === "pick") { + startPicker(msg.tabId, "review").then(() => reply({ ok: true })); + return true; + } + return false; +}); diff --git a/extensions/browser/src/content.js b/extensions/browser/src/content.js new file mode 100644 index 000000000..1e5c51e3e --- /dev/null +++ b/extensions/browser/src/content.js @@ -0,0 +1,30 @@ +// Injected into the tab when the user clips. It clips in place and answers the extension; it keeps nothing. +import { clip } from "./core/clip.js"; +import { pick } from "./core/picker.js"; + +const ext = globalThis.browser ?? globalThis.chrome; + +if (!globalThis.__lensClipper) { + globalThis.__lensClipper = { + /** Clip now: the page or the selection. */ + run({ mode, settings, tags }) { + try { + return { ok: true, clip: clip(document, { mode, settings, tags }) }; + } catch (e) { + return { ok: false, error: e.message }; + } + }, + /** Start the picker; the pick goes to the extension as a "picked" message, since the popup closes meanwhile. */ + async pick({ settings, tags, intent }) { + const el = await pick(document); + if (!el) return; + let answer; + try { + answer = { ok: true, clip: clip(document, { mode: "element", element: el, settings, tags }) }; + } catch (e) { + answer = { ok: false, error: e.message }; + } + await ext.runtime.sendMessage({ type: "picked", intent, ...answer }); + }, + }; +} diff --git a/extensions/browser/src/core/clip.js b/extensions/browser/src/core/clip.js new file mode 100644 index 000000000..1ae1bc736 --- /dev/null +++ b/extensions/browser/src/core/clip.js @@ -0,0 +1,72 @@ +// Turning what's on the page into a clip: a full page (through Readability), the selection, or one picked element. +import { Readability } from "@mozilla/readability"; +import { toMarkdown, prepare } from "./markdown.js"; +import { extractMetadata } from "./metadata.js"; +import { render } from "./template.js"; + +function selectionHtml(doc) { + const sel = doc.getSelection?.(); + if (!sel || sel.isCollapsed || !sel.rangeCount) return ""; + const box = doc.createElement("div"); + for (let i = 0; i < sel.rangeCount; i++) { + const range = sel.getRangeAt(i); + // a selection inside a list, table, quote or code block keeps that structure around it + const holder = range.commonAncestorContainer.nodeType === 1 ? range.commonAncestorContainer : range.commonAncestorContainer.parentNode; + const wrap = holder?.matches?.("ul, ol") ? holder : holder?.closest?.("pre, code, li, table, blockquote"); + const piece = range.cloneContents(); + if (wrap) { + const shell = wrap.cloneNode(false); + shell.append(piece); + box.append(shell); + } else box.append(piece); + } + return box.innerHTML; +} + +function article(doc) { + const parsed = new Readability(doc.cloneNode(true), { keepClasses: true }).parse(); + return parsed?.content ? parsed : null; +} + +/** + * Clip a document. `mode` is "page", "selection" or "element" (with `element`). Returns + * {title, markdown, url, images, clipType}: `markdown` is the whole rendered template. + */ +export function clip(doc, { mode = "page", element = null, settings, tags = [], now = new Date() }) { + const meta = extractMetadata(doc, doc.URL); + let html = ""; + let clipType = mode; + if (mode === "selection") { + html = selectionHtml(doc); + if (!html) throw new Error("Select some text on the page first"); + } else if (mode === "element") { + if (!element) throw new Error("Pick something on the page first"); + html = element.outerHTML; + } else { + clipType = "page"; + const a = settings.readability ? article(doc) : null; + if (a) { + html = a.content; + meta.title = meta.title || a.title || ""; + meta.byline = meta.byline || a.byline || ""; + meta.excerpt = meta.excerpt || a.excerpt || ""; + meta.siteName = meta.siteName || a.siteName || ""; + meta.published = meta.published || (a.publishedTime ? new Date(a.publishedTime).toISOString() : ""); + meta.lang = meta.lang || a.lang || ""; + } else html = doc.body?.innerHTML ?? ""; + } + + // an inert document: nothing in the clipped HTML runs or loads while it's converted + const inert = doc.implementation.createHTMLDocument(""); + const box = inert.createElement("div"); + box.innerHTML = html; + const images = prepare(box, doc.baseURI || meta.url); + const content = toMarkdown(box.innerHTML, settings.markdown); + if (!meta.excerpt) meta.excerpt = box.querySelector("p")?.textContent.trim().slice(0, 300) ?? ""; + + const vars = { ...meta, content, tags, date: now, clipType }; + const title = render(settings.titleTemplate || "{title}", vars).trim() || meta.title || meta.url; + const template = (clipType !== "page" && settings.selectionTemplate) || settings.template; + const markdown = render(template, { ...vars, title }).trim() + "\n"; + return { title, markdown, url: meta.url, images, clipType, image: meta.image }; +} diff --git a/extensions/browser/src/core/lens.js b/extensions/browser/src/core/lens.js new file mode 100644 index 000000000..a0de3928f --- /dev/null +++ b/extensions/browser/src/core/lens.js @@ -0,0 +1,100 @@ +// Sending clips to a Lens server through its import webhooks (docs/api.md, Import webhooks): a namespace's owners make +// a hook in Lens, and its token is all the clipper needs. + +export const PUSH_PATH = "/api/v1/hooks/import"; +const MAX_FILES = 20; // the server takes at most 20 files a push + +async function explain(res) { + let detail = ""; + try { + const body = await res.json(); + detail = typeof body.detail === "string" ? body.detail : JSON.stringify(body.detail ?? body); + } catch { + // not JSON + } + if (res.status === 401) return "Lens didn't recognise this token: make a new import webhook and paste its token"; + if (res.status === 403) return detail || "this import webhook is paused in Lens"; + if (res.status === 413) return detail || "that's more than this Lens takes at once"; + return detail || `Lens answered ${res.status} ${res.statusText}`; +} + +const filenameFor = (src, i, type) => { + let name = ""; + try { + name = decodeURIComponent(new URL(src).pathname.split("/").pop() ?? ""); + } catch { + // keep the fallback + } + name = name.replace(/[^\w.-]+/g, "-").slice(-80); + if (!/\.(png|jpe?g|gif|webp|avif|svg|bmp|tiff?)$/i.test(name)) { + const ext = { "image/png": "png", "image/gif": "gif", "image/webp": "webp", "image/svg+xml": "svg", "image/avif": "avif" }[type] ?? "jpg"; + name = `image-${i + 1}.${ext}`; + } + return name; +}; + +/** Fetch the clip's images, as many as fit, skipping any that fail. */ +export async function fetchImages(urls, { max = 10, fetchImpl = fetch } = {}) { + const out = []; + for (const [i, src] of urls.slice(0, Math.min(max, MAX_FILES - 1)).entries()) { + try { + const res = await fetchImpl(src, { credentials: "omit" }); + if (!res.ok) continue; + const blob = await res.blob(); + if (!blob.type.startsWith("image/")) continue; + out.push({ name: filenameFor(src, i, blob.type), blob }); + } catch { + // an image that can't be fetched is left as a link in the Markdown + } + } + return out; +} + +/** + * Push a clip: its Markdown as text (Lens imports it like pasted text), plus, when asked, its images as files and its + * address for Lens to capture itself. Resolves to the server's answer: {namespace, items: [{kind, name, recording}]}. + */ +export async function push({ server, token }, { title, markdown, url }, { images = [], captureUrl = false, fetchImpl = fetch } = {}) { + if (!token) throw new Error("add this Lens's import webhook token in the clipper's options"); + const headers = { Authorization: `Bearer ${token}`, Accept: "application/json" }; + let body; + if (!images.length && !captureUrl) { + headers["Content-Type"] = "application/json"; + body = JSON.stringify({ text: markdown, title: title.slice(0, 200) }); + } else { + body = new FormData(); + body.append("text", markdown); + body.append("title", title.slice(0, 200)); + if (captureUrl && /^https?:/.test(url)) body.append("url", url); + for (const img of images) body.append("file", img.blob, img.name); + } + let res; + try { + res = await fetchImpl(`${server}${PUSH_PATH}`, { method: "POST", headers, body, credentials: "omit" }); + } catch (e) { + throw new Error(`couldn't reach ${server}: ${e.message}`); + } + if (!res.ok) throw new Error(await explain(res)); + return res.json(); +} + +/** Check an address and token without importing anything: an empty push is refused with 400 once the token is known. */ +export async function check({ server, token }, { fetchImpl = fetch } = {}) { + let res; + try { + res = await fetchImpl(`${server}${PUSH_PATH}`, { + method: "POST", + headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json", Accept: "application/json" }, + body: "{}", + credentials: "omit", + }); + } catch (e) { + return { ok: false, message: `couldn't reach ${server}: ${e.message}` }; + } + if (res.status === 400) return { ok: true, message: "Connected: clips will go into this hook's namespace" }; + if (res.status === 404) return { ok: false, message: "that address answers, but not as a Lens (no import webhooks there)" }; + return { ok: false, message: await explain(res) }; +} + +/** Where a pushed item can be opened in Lens. */ +export const itemLink = (server, item) => `${server}/recordings/${item.recording}`; diff --git a/extensions/browser/src/core/markdown.js b/extensions/browser/src/core/markdown.js new file mode 100644 index 000000000..ad8e93e03 --- /dev/null +++ b/extensions/browser/src/core/markdown.js @@ -0,0 +1,126 @@ +// HTML to Markdown with Turndown, configured from the clipper's settings (the same knobs MarkDownload offers). +import TurndownService from "turndown"; +import { gfm } from "turndown-plugin-gfm"; + +const DROP = "script, style, noscript, template, link, meta, button, input, select, textarea, form, dialog, svg[aria-hidden='true']"; +const LAZY_SRC = ["data-src", "data-lazy-src", "data-original", "data-url", "data-hi-res-src"]; + +const absolute = (href, base) => { + try { + return new URL(href, base).href; + } catch { + return href; + } +}; + +/** Clean a container of clipped nodes in place: absolute links and images, lazy images loaded, page chrome removed. + * Returns the image addresses it kept, in order. */ +export function prepare(root, base) { + for (const el of root.querySelectorAll(DROP)) el.remove(); + for (const el of root.querySelectorAll("[hidden], [aria-hidden='true']")) { + if (!el.querySelector("img, picture")) el.remove(); + } + for (const pic of root.querySelectorAll("picture")) { + const img = pic.querySelector("img"); + const source = pic.querySelector("source[srcset]"); + if (img && !img.getAttribute("src") && source) img.setAttribute("src", source.getAttribute("srcset").split(/[\s,]+/)[0]); + for (const s of pic.querySelectorAll("source")) s.remove(); + } + const images = []; + for (const img of root.querySelectorAll("img")) { + let src = img.getAttribute("src") ?? ""; + const lazy = LAZY_SRC.map((a) => img.getAttribute(a)).find(Boolean); + if (lazy && (!src || src.startsWith("data:image/gif") || src.startsWith("data:image/svg"))) src = lazy; + if (!src) { + const set = img.getAttribute("srcset") || img.getAttribute("data-srcset"); + if (set) src = set.trim().split(/[\s,]+/)[0]; + } + if (!src) { + img.remove(); + continue; + } + src = src.startsWith("data:") ? src : absolute(src, base); + img.setAttribute("src", src); + img.removeAttribute("srcset"); + if (!src.startsWith("data:")) images.push(src); + } + for (const a of root.querySelectorAll("a[href]")) { + const href = a.getAttribute("href"); + if (/^\s*javascript:/i.test(href)) a.removeAttribute("href"); + else if (!href.startsWith("#")) a.setAttribute("href", absolute(href, base)); + } + return [...new Set(images)]; +} + +export const MARKDOWN_DEFAULTS = { + headingStyle: "atx", // or setext + hr: "---", + bulletListMarker: "-", + codeBlockStyle: "fenced", // or indented + fence: "```", + emDelimiter: "_", + strongDelimiter: "**", + linkStyle: "inlined", // or referenced + linkReferenceStyle: "full", + images: "keep", // keep | alt (only their alt text) | drop + links: "keep", // keep | text (only their text) + tables: true, // GitHub-flavoured tables, strikethrough and task lists +}; + +/** A Turndown converter for these settings. */ +export function converter(options = {}) { + const o = { ...MARKDOWN_DEFAULTS, ...options }; + const td = new TurndownService({ + headingStyle: o.headingStyle, + hr: o.hr, + bulletListMarker: o.bulletListMarker, + codeBlockStyle: o.codeBlockStyle, + fence: o.fence, + emDelimiter: o.emDelimiter, + strongDelimiter: o.strongDelimiter, + linkStyle: o.linkStyle, + linkReferenceStyle: o.linkReferenceStyle, + }); + if (o.tables) td.use(gfm); + td.remove(["script", "style", "noscript", "iframe", "object", "embed"]); + + // fenced code keeps its language (class="language-js", "lang-js", "highlight-source-js") + if (o.codeBlockStyle === "fenced") { + td.addRule("fencedWithLanguage", { + filter: (node) => node.nodeName === "PRE" && node.textContent.trim() !== "", + replacement: (_content, node) => { + const code = node.querySelector("code") ?? node; + const cls = `${code.getAttribute("class") ?? ""} ${node.getAttribute("class") ?? ""} ${node.parentNode?.getAttribute?.("class") ?? ""}`; + const lang = /(?:language|lang|highlight-source)-([\w+#-]+)/.exec(cls)?.[1] ?? code.getAttribute("data-lang") ?? ""; + const text = code.textContent.replace(/\n$/, ""); + let fence = o.fence; + while (text.includes(fence)) fence += o.fence[0]; + return `\n\n${fence}${lang}\n${text}\n${fence}\n\n`; + }, + }); + } + if (o.images === "drop") td.addRule("imageDrop", { filter: "img", replacement: () => "" }); + if (o.images === "alt") td.addRule("imageAlt", { filter: "img", replacement: (_c, node) => node.getAttribute("alt") || "" }); + if (o.images === "keep") { + td.addRule("image", { + filter: "img", + replacement: (_c, node) => { + const src = node.getAttribute("src"); + if (!src) return ""; + const alt = (node.getAttribute("alt") || "").replace(/[[\]\n]/g, " ").trim(); + const title = node.getAttribute("title"); + return `![${alt}](${src.replace(/ /g, "%20")}${title ? ` "${title.replace(/"/g, '\\"')}"` : ""})`; + }, + }); + } + if (o.links === "text") td.addRule("linkText", { filter: "a", replacement: (content) => content }); + return td; +} + +/** HTML (a string) to Markdown. */ +export function toMarkdown(html, options) { + return converter(options) + .turndown(html) + .replace(/\n{3,}/g, "\n\n") + .trim(); +} diff --git a/extensions/browser/src/core/metadata.js b/extensions/browser/src/core/metadata.js new file mode 100644 index 000000000..87429a47b --- /dev/null +++ b/extensions/browser/src/core/metadata.js @@ -0,0 +1,97 @@ +// A page's metadata, from its tags, Open Graph, JSON-LD and the document itself. + +const meta = (doc, ...names) => { + for (const n of names) { + const el = doc.querySelector(`meta[property="${n}"], meta[name="${n}"], meta[itemprop="${n}"]`); + const v = el?.getAttribute("content")?.trim(); + if (v) return v; + } + return ""; +}; + +function jsonLd(doc) { + const found = []; + for (const s of doc.querySelectorAll('script[type="application/ld+json"]')) { + try { + const data = JSON.parse(s.textContent); + const stack = [data]; + while (stack.length) { + const x = stack.pop(); + if (Array.isArray(x)) stack.push(...x); + else if (x && typeof x === "object") { + if (x["@graph"]) stack.push(x["@graph"]); + found.push(x); + } + } + } catch { + // a broken JSON-LD block says nothing + } + } + const article = found.find((x) => /Article|BlogPosting|NewsArticle|WebPage|Report/.test([].concat(x["@type"] ?? []).join(" "))); + if (!article) return {}; + const name = (a) => (typeof a === "string" ? a : a?.name ?? ""); + const authors = [].concat(article.author ?? []).map(name).filter(Boolean); + const image = [].concat(article.image ?? [])[0]; + return { + author: authors.join(", "), + published: article.datePublished ?? "", + modified: article.dateModified ?? "", + headline: article.headline ?? "", + image: typeof image === "string" ? image : image?.url ?? "", + keywords: [].concat(article.keywords ?? []).flatMap((k) => String(k).split(",")), + }; +} + +const absolute = (href, base) => { + if (!href) return ""; + try { + return new URL(href, base).href; + } catch { + return ""; + } +}; + +const isoDate = (s) => { + if (!s) return ""; + const d = new Date(s); + return Number.isNaN(d.getTime()) ? "" : d.toISOString(); +}; + +/** Everything templates can use about the page itself (not the clipped content). */ +export function extractMetadata(doc, pageUrl = doc.URL) { + const ld = jsonLd(doc); + const canonical = doc.querySelector('link[rel="canonical"]')?.getAttribute("href"); + const url = absolute(canonical, pageUrl) || pageUrl; + let host = ""; + let origin = ""; + try { + ({ host, origin } = new URL(url)); + } catch { + // about: and file: pages have no host + } + const keywords = [ + ...meta(doc, "keywords", "news_keywords").split(","), + ...[...doc.querySelectorAll('meta[property="article:tag"]')].map((m) => m.getAttribute("content") ?? ""), + ...(ld.keywords ?? []), + ] + .map((k) => k.trim()) + .filter(Boolean); + return { + title: meta(doc, "og:title", "twitter:title") || ld.headline || doc.title?.trim() || "", + url, + domain: host.replace(/^www\./, ""), + origin, + siteName: meta(doc, "og:site_name", "application-name") || host.replace(/^www\./, ""), + byline: meta(doc, "author", "article:author", "parsely-author", "sailthru.author") || ld.author || "", + excerpt: meta(doc, "description", "og:description", "twitter:description"), + published: isoDate( + meta(doc, "article:published_time", "datePublished", "date", "DC.date.issued", "dcterms.created") || + ld.published || + doc.querySelector("time[datetime]")?.getAttribute("datetime"), + ), + modified: isoDate(meta(doc, "article:modified_time", "dateModified", "dcterms.modified") || ld.modified), + image: absolute(meta(doc, "og:image", "og:image:url", "twitter:image") || ld.image, pageUrl), + keywords: [...new Set(keywords)], + lang: doc.documentElement?.getAttribute("lang") || meta(doc, "og:locale") || "", + }; +} diff --git a/extensions/browser/src/core/picker.js b/extensions/browser/src/core/picker.js new file mode 100644 index 000000000..fe6a4a841 --- /dev/null +++ b/extensions/browser/src/core/picker.js @@ -0,0 +1,79 @@ +// Picking one element on the page: hover to outline it, click to take it, ↑/↓ to widen or narrow, Esc to stop. + +const Z = "2147483647"; + +export function pick(doc = document) { + return new Promise((resolve) => { + const win = doc.defaultView; + const box = doc.createElement("div"); + const tip = doc.createElement("div"); + Object.assign(box.style, { + position: "fixed", + pointerEvents: "none", + zIndex: Z, + border: "2px solid #6d5dfc", + background: "rgba(109, 93, 252, 0.12)", + borderRadius: "3px", + transition: "all 60ms ease-out", + }); + Object.assign(tip.style, { + position: "fixed", + zIndex: Z, + pointerEvents: "none", + left: "50%", + bottom: "16px", + transform: "translateX(-50%)", + font: "13px/1.4 system-ui, sans-serif", + color: "#fff", + background: "rgba(20, 20, 30, 0.92)", + padding: "8px 12px", + borderRadius: "8px", + boxShadow: "0 4px 16px rgba(0,0,0,.25)", + }); + tip.textContent = "Lens: click to clip · ↑ wider · ↓ narrower · Esc to cancel"; + doc.documentElement.append(box, tip); + + let current = null; + const trail = []; + const show = (el) => { + current = el; + const r = el.getBoundingClientRect(); + Object.assign(box.style, { left: `${r.left - 2}px`, top: `${r.top - 2}px`, width: `${r.width + 4}px`, height: `${r.height + 4}px` }); + tip.textContent = `Lens: ${el.tagName.toLowerCase()}${el.id ? `#${el.id}` : ""} · click to clip · ↑ wider · ↓ narrower · Esc to cancel`; + }; + const finish = (el) => { + win.removeEventListener("mousemove", onMove, true); + win.removeEventListener("click", onClick, true); + win.removeEventListener("keydown", onKey, true); + box.remove(); + tip.remove(); + resolve(el); + }; + const onMove = (e) => { + const el = doc.elementFromPoint(e.clientX, e.clientY); + if (el && el !== current && el !== box && el !== tip) { + trail.length = 0; + show(el); + } + }; + const onClick = (e) => { + e.preventDefault(); + e.stopPropagation(); + finish(current); + }; + const onKey = (e) => { + if (e.key === "Escape") finish(null); + else if (e.key === "ArrowUp" && current?.parentElement && current.parentElement !== doc.documentElement) { + trail.push(current); + show(current.parentElement); + } else if (e.key === "ArrowDown" && trail.length) show(trail.pop()); + else if (e.key === "Enter" && current) finish(current); + else return; + e.preventDefault(); + e.stopPropagation(); + }; + win.addEventListener("mousemove", onMove, true); + win.addEventListener("click", onClick, true); + win.addEventListener("keydown", onKey, true); + }); +} diff --git a/extensions/browser/src/core/settings.js b/extensions/browser/src/core/settings.js new file mode 100644 index 000000000..f07675190 --- /dev/null +++ b/extensions/browser/src/core/settings.js @@ -0,0 +1,83 @@ +// The clipper's settings. Everything but the tokens syncs across the user's browsers; tokens stay on this device. +import { MARKDOWN_DEFAULTS } from "./markdown.js"; + +export const DEFAULT_TEMPLATE = `--- +title: {title|yaml} +source: {url} +author: {byline|yaml} +site: {siteName|yaml} +published: {published:YYYY-MM-DD} +clipped: {date:YYYY-MM-DDTHH:mm:ssZ} +image: {image} +tags: {tags|list} +--- + +# {title} + +{content} +`; + +export const DEFAULTS = { + destinations: [], // [{id, name, server}]; each one's token is in local storage under token: + defaultDestination: "", + template: DEFAULT_TEMPLATE, + titleTemplate: "{title}", + selectionTemplate: "", // blank: the same template as pages + markdown: { ...MARKDOWN_DEFAULTS }, + readability: true, // full pages: keep the article, not the menus and footers + sendImages: false, // also push the content's images as files (they become resources in Lens) + maxImages: 10, + captureOnServer: false, // also ask Lens to capture the page itself (needs Chromium on the server) + reviewQuickClips: false, // context menu and shortcut clips open the popup instead of sending straight away + tags: [], +}; + +const ext = globalThis.browser ?? globalThis.chrome; + +export async function load() { + const stored = await ext.storage.sync.get(Object.keys(DEFAULTS)); + const s = { ...structuredClone(DEFAULTS), ...stored }; + s.markdown = { ...MARKDOWN_DEFAULTS, ...(stored.markdown ?? {}) }; + return s; +} + +export async function save(patch) { + await ext.storage.sync.set(patch); +} + +export async function token(id) { + const key = `token:${id}`; + return (await ext.storage.local.get(key))[key] ?? ""; +} + +export async function setToken(id, value) { + if (value) await ext.storage.local.set({ [`token:${id}`]: value }); + else await ext.storage.local.remove(`token:${id}`); +} + +export function destination(settings, id) { + const all = settings.destinations ?? []; + return all.find((d) => d.id === (id || settings.defaultDestination)) ?? all[0] ?? null; +} + +// plain http is fine on this computer or the local network, nowhere else +export const isLocal = (host) => + host === "localhost" || + host === "[::1]" || + host.endsWith(".local") || + host.endsWith(".lan") || + /^(127|10)\.\d+\.\d+\.\d+$/.test(host) || + /^192\.168\.\d+\.\d+$/.test(host) || + /^172\.(1[6-9]|2\d|3[01])\.\d+\.\d+$/.test(host); + +/** A server's address as its origin plus any base path, without a trailing slash. */ +export function normalizeServer(input) { + let s = String(input ?? "").trim(); + if (!s) throw new Error("enter your Lens address"); + if (!/^https?:\/\//i.test(s)) s = `https://${s}`; + const u = new URL(s); + if (u.protocol === "http:" && !isLocal(u.hostname)) { + throw new Error("use https:// for a Lens that isn't on this computer or network"); + } + return `${u.origin}${u.pathname.replace(/\/+$/, "")}`; +} diff --git a/extensions/browser/src/core/template.js b/extensions/browser/src/core/template.js new file mode 100644 index 000000000..9bba4f95b --- /dev/null +++ b/extensions/browser/src/core/template.js @@ -0,0 +1,141 @@ +// MarkDownload-style templates: {variable}, {date:YYYY-MM-DD}, {title|kebab|lower}. `{{` and `}}` are literal braces. +// Unknown variables render as nothing, so a template never fails on a page that lacks something. + +const pad = (n, w = 2) => String(n).padStart(w, "0"); + +/** Format a date with YYYY YY MM M DD D HH H mm ss Z (local time; Z is the +hh:mm offset). Other text is kept. */ +export function formatDate(value, format) { + const d = value instanceof Date ? value : new Date(value); + if (Number.isNaN(d.getTime())) return ""; + if (!format) return d.toISOString(); + const off = -d.getTimezoneOffset(); + const tokens = { + YYYY: () => String(d.getFullYear()), + YY: () => String(d.getFullYear()).slice(-2), + MM: () => pad(d.getMonth() + 1), + M: () => String(d.getMonth() + 1), + DD: () => pad(d.getDate()), + D: () => String(d.getDate()), + HH: () => pad(d.getHours()), + H: () => String(d.getHours()), + mm: () => pad(d.getMinutes()), + ss: () => pad(d.getSeconds()), + Z: () => `${off >= 0 ? "+" : "-"}${pad(Math.floor(Math.abs(off) / 60))}:${pad(Math.abs(off) % 60)}`, + }; + return format.replace(/YYYY|YY|MM|M|DD|D|HH|H|mm|ss|Z/g, (t) => tokens[t]()); +} + +const words = (s) => + String(s) + .normalize("NFKD") + .replace(/[̀-ͯ]/g, "") + .replace(/([a-z0-9])([A-Z])/g, "$1 $2") + .split(/[^A-Za-z0-9]+/) + .filter(Boolean); + +const asText = (v) => (Array.isArray(v) ? v.join(", ") : v == null ? "" : String(v)); + +export const FILTERS = { + lower: (v) => asText(v).toLowerCase(), + upper: (v) => asText(v).toUpperCase(), + trim: (v) => asText(v).trim(), + kebab: (v) => words(asText(v)).join("-").toLowerCase(), + snake: (v) => words(asText(v)).join("_").toLowerCase(), + camel: (v) => + words(asText(v)) + .map((w, i) => (i ? w[0].toUpperCase() + w.slice(1).toLowerCase() : w.toLowerCase())) + .join(""), + pascal: (v) => + words(asText(v)) + .map((w) => w[0].toUpperCase() + w.slice(1).toLowerCase()) + .join(""), + title: (v) => asText(v).replace(/\b\p{L}/gu, (c) => c.toUpperCase()), + // a file name that every OS accepts + filename: (v) => + asText(v) + .replace(/[\\/:*?"<>|\u0000-\u001f]+/g, " ") + .replace(/\s+/g, " ") + .trim() + .slice(0, 150), + // a YAML scalar: quoted only when it has to be + yaml: (v) => { + const s = asText(v); + if (s === "") return ""; + return /^[\w][\w .,/()&'-]*$/u.test(s) && !/^(true|false|null|yes|no|on|off|~|\d[\d.:-]*)$/i.test(s) && !/:\s|\s#/.test(s) + ? s + : JSON.stringify(s); + }, + // a YAML flow list: ["a", "b"] + list: (v) => JSON.stringify((Array.isArray(v) ? v : asText(v) ? [asText(v)] : []).map(String)), + // tags as #hashtags + hashtags: (v) => + (Array.isArray(v) ? v : asText(v).split(",")) + .map((t) => words(t).join("-")) + .filter(Boolean) + .map((t) => `#${t}`) + .join(" "), + json: (v) => JSON.stringify(v ?? ""), + first: (v) => (Array.isArray(v) ? asText(v[0]) : asText(v)), +}; + +const DATE_VARS = new Set(["date", "published", "modified"]); + +function resolve(vars, expr) { + const [head, ...rest] = expr.split("|"); + const filters = rest.map((f) => f.trim()); + const colon = head.indexOf(":"); + const name = (colon < 0 ? head : head.slice(0, colon)).trim(); + const arg = colon < 0 ? null : head.slice(colon + 1); // kept as typed: {keywords:, } joins with a comma and a space + let value = vars[name]; + if (DATE_VARS.has(name) && value) value = formatDate(value, arg); + else if (arg != null && Array.isArray(value)) value = value.join(arg); + for (const f of filters) { + const fn = FILTERS[f]; + if (fn) value = fn(value); + } + return asText(value); +} + +/** Render a template with the clip's variables. */ +export function render(template, vars) { + const out = String(template ?? "") + .replace(/\{\{/g, "\u0000") + .replace(/\}\}/g, "\u0001") + .replace(/\{([^{}\n]+)\}/g, (_, expr) => resolve(vars, expr)) + .replace(/\u0000/g, "{") + .replace(/\u0001/g, "}"); + return dropEmptyFrontMatter(out); +} + +// A front matter line with nothing after its key (`author:`, `author: ""`) is dropped, so pages without an author don't +// leave empty fields behind. A key followed by an indented block (a YAML list) is kept. +function dropEmptyFrontMatter(text) { + const m = /^---\r?\n([\s\S]*?)\r?\n---(\r?\n|$)/.exec(text); + if (!m) return text; + const lines = m[1].split(/\r?\n/); + const kept = lines.filter((line, i) => { + if (!/^[\w-]+:\s*(""|'')?\s*$/.test(line)) return true; + return /^\s+\S/.test(lines[i + 1] ?? ""); + }); + return `---\n${kept.join("\n")}\n---${m[2]}${text.slice(m[0].length)}`; +} + +/** The variables a clip offers to templates, shown in the options page. */ +export const VARIABLES = { + title: "the page's (or your edited) title", + url: "the page's address (its canonical one when it has one)", + domain: "the site's host name", + origin: "scheme and host", + siteName: "the site's name", + byline: "the author", + excerpt: "a summary: the page's description or first paragraph", + published: "when it was published; {published:YYYY-MM-DD}", + modified: "when it was last changed", + date: "now; {date:YYYY-MM-DD HH:mm}", + keywords: "the page's keywords; {keywords:, } joins them", + tags: "the tags you add", + image: "the page's lead image", + lang: "the page's language", + clipType: "page, selection or element", + content: "the clipped content as Markdown", +}; diff --git a/extensions/browser/src/icons/icon-128.png b/extensions/browser/src/icons/icon-128.png new file mode 100644 index 0000000000000000000000000000000000000000..7e8bbc656a3951913370d47f0066b465e39250b1 GIT binary patch literal 7301 zcmbtZWmMGBxBU${Ai@kKNX^hKNJ@8uq_i*~DcvCq%}6Q@BHdlm4T3Z%B`MM&-TCML z;l1x~y>-{Vcinr>{&3g6`>b`=`KYcY{}lH*E&u>e6%}MOAJ>5Y0*v-Js~DZ90|3a; zMp|0k#@rkLm_NIJ7FI@=Bo6JMSCXM)A%<2fWSe~sU`CndR#)NBYIGH;dYlj*>v<5- z&*Jiv28CL$mLAerv(2)CgJ@BDhS#?AWu7&GDEivrrC1(UPS3F*;kYT+H$%j0$Fe*^ z6!`4@Z_t(m=8ndD=*^uMUlwd`((xKE6EteK5fr~2Ip8y*`k0p=T&n72Bru#)r6T<< z*P3|=x@g4m!20anPdB# z_hj;A+*Lkiv0u$iHR`2u3hf;m$XYlzlMsZ zl!3@6oE5ui^#sZD<2UbmN4#{7e|QvX9{S^d<=$!zKG$I?oqJ^!Th++Yu|ZT7pDgZNA&{PEgAI3*XLIB|UztU_0fIAle?3e<8PznG%b4qX45P7`7 zGEj@I*A7c?=x3o z_!hM-80j&j!X=0qG(KgM-;yPSgUupy&fl+3pem=5_AAeP5AFU9^f{dU&ie5y3_B>+ zVR8ock_b-$l4=tN;fXKa5MHjmFgS?y+gF7b3+pU4CyuqWf4OegUUVH@+HJU)doRXJ zJDzP93;1(2 z=z2r%+qGqGGVAWjN;dMjG6d69b2L#_yb6V%rw5o970!q{tDXi$wtg$j+8sGw!IGQYJ5wz(K<-L3&|33sAV;{0XL2(r4Wu2Mn_XJ&|x79gfl z5W@!cBN8W+#Ry+*qMiC7umE~A;bnbv=^;=`;~@#6{>QRma?4TmLIoloW!ftXHT90K z*p8rf^L^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|x+$2Wx}UZdJ%eWZzra|KOTNDbGTN!&m@RA;j*go_TC$^-Yt^3@}n` za6`1}bJp0wjF{?POh0$Ct{IzY^fo97U?J5k>u}Gaj{B~vbQWdjpbkYgya)*p6N<9E zU;7)ajm@)kVle+n7P>6bq@f0k8Hv|k>o?v_$-v_DfH)x0j@?S{)zu4os`|?{^+#W9 zytTs*MJ57AILF?qE}7qU&!P^mmPVY$ltBB}#j7u{#?I00WS(>f8tD+14a0g;OT#;i z?B&hT3!9o7w#PdMwcfPP%*fpI#r9O!Ek_)jNi6cgS@*b^OU!%{cjExs&s3^#Y2>EI z$?zj$uZSL#$;`;M%tf!VIMYnYePnZ3H)zS;1e2QDt9eDNrfNwS(4uL{i-Z{^FpZ^h zN-+PgEKIgYDbCF30*mU_w;liv$hG6R(qnp2Mkfp$T`LPXwutvO{wPdc*7OvyC`M3V z$B6*I{Q-{rj*)wfgTBGOOw#!&^U7R%aK=wroMq+@%xj0Gq5o4>YX>Q|%$;AKw002ovPDHLk FV1g5_fxQ3# literal 0 HcmV?d00001 diff --git a/extensions/browser/src/manifest.json b/extensions/browser/src/manifest.json new file mode 100644 index 000000000..3abfd5f85 --- /dev/null +++ b/extensions/browser/src/manifest.json @@ -0,0 +1,24 @@ +{ + "manifest_version": 3, + "name": "Lens Web Clipper", + "short_name": "Lens Clipper", + "description": "Clip pages, selections or any part of a page into your Lens as Markdown, with its metadata and images.", + "version": "0.0.0", + "icons": { "16": "icons/icon-16.png", "32": "icons/icon-32.png", "48": "icons/icon-48.png", "128": "icons/icon-128.png" }, + "action": { + "default_title": "Clip to Lens", + "default_popup": "popup.html", + "default_icon": { "16": "icons/icon-16.png", "32": "icons/icon-32.png" } + }, + "background": { "service_worker": "background.js" }, + "options_ui": { "page": "options.html", "open_in_tab": true }, + "permissions": ["activeTab", "scripting", "contextMenus", "storage"], + "optional_host_permissions": ["https://*/*", "http://*/*"], + "commands": { + "_execute_action": { "suggested_key": { "default": "Alt+Shift+L" }, "description": "Open the clipper" }, + "clip-page": { "suggested_key": { "default": "Alt+Shift+P" }, "description": "Clip this page to Lens" }, + "clip-selection": { "suggested_key": { "default": "Alt+Shift+S" }, "description": "Clip the selection to Lens" }, + "pick": { "suggested_key": { "default": "Alt+Shift+K" }, "description": "Pick part of the page to clip" } + }, + "content_security_policy": { "extension_pages": "script-src 'self'; object-src 'self'" } +} diff --git a/extensions/browser/src/ui/options.html b/extensions/browser/src/ui/options.html new file mode 100644 index 000000000..fd9bc1db2 --- /dev/null +++ b/extensions/browser/src/ui/options.html @@ -0,0 +1,94 @@ + + + + + Lens clipper options + + + + +

Lens clipper

+ +

Your Lens

+

+ In Lens, open a namespace's admin page and make an import webhook; paste its address and token here. Clips go into that + namespace. Add one per namespace you clip into. +

+
+
+
+
+
+
+ + +

+
+ +

Template

+

Variables in braces, with filters after a bar: {title|kebab}, dates with a format: {date:YYYY-MM-DD}.

+ + + + + + +

+
+ Variables and filters +
+

+
+ + + +

Markdown

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +

Clipping

+ + + + + + +

Shortcuts: Alt+Shift+L opens the clipper, Alt+Shift+P clips the page, Alt+Shift+S the selection, Alt+Shift+K picks. Change them in + your browser's extension shortcuts.

+ +

+ + + diff --git a/extensions/browser/src/ui/options.js b/extensions/browser/src/ui/options.js new file mode 100644 index 000000000..ce975a3cd --- /dev/null +++ b/extensions/browser/src/ui/options.js @@ -0,0 +1,177 @@ +// The options page: where clips go, the template, Markdown style and clipping choices. Changes save as they're made. +import * as settingsStore from "../core/settings.js"; +import { check } from "../core/lens.js"; +import { FILTERS, VARIABLES } from "../core/template.js"; + +const ext = globalThis.browser ?? globalThis.chrome; +const $ = (id) => document.getElementById(id); +let settings; + +function saved(text = "Saved", kind = "ok") { + $("saved").className = `status ${kind}`; + $("saved").textContent = text; + clearTimeout(saved.t); + saved.t = setTimeout(() => ($("saved").textContent = ""), 2000); +} + +async function patch(p) { + Object.assign(settings, p); + await settingsStore.save(p); + saved(); +} + +const originPattern = (server) => `${new URL(server).origin}/*`; + +// ---------- destinations ---------- +function renderDestinations() { + const box = $("destinations"); + box.replaceChildren( + ...settings.destinations.map((d) => { + const el = document.createElement("div"); + el.className = "dest"; + const isDefault = d.id === settings.defaultDestination || (!settings.defaultDestination && d === settings.destinations[0]); + const row = document.createElement("div"); + row.className = "row"; + const name = document.createElement("div"); + name.className = "grow"; + const strong = document.createElement("strong"); + strong.textContent = d.name || "Lens"; + const where = document.createElement("div"); + where.className = "hint"; + where.textContent = d.server; + name.append(strong, isDefault ? " (default)" : "", where); + const state = document.createElement("span"); + state.className = "status"; + const button = (label, fn) => { + const b = document.createElement("button"); + b.textContent = label; + b.addEventListener("click", fn); + return b; + }; + row.append( + name, + button("Check", async () => { + state.textContent = "Checking…"; + const r = await check({ server: d.server, token: await settingsStore.token(d.id) }); + state.className = `status ${r.ok ? "ok" : "bad"}`; + state.textContent = r.message; + }), + ...(isDefault ? [] : [button("Make default", () => patch({ defaultDestination: d.id }).then(renderDestinations))]), + button("Remove", async () => { + await settingsStore.setToken(d.id, ""); + const destinations = settings.destinations.filter((x) => x.id !== d.id); + await patch({ destinations, defaultDestination: isDefault ? destinations[0]?.id ?? "" : settings.defaultDestination }); + renderDestinations(); + }), + ); + el.append(row, state); + return el; + }), + ); +} + +$("add").addEventListener("click", () => { + const out = $("addStatus"); + let server; + try { + server = settingsStore.normalizeServer($("newServer").value); + } catch (e) { + out.className = "status bad"; + out.textContent = e.message; + return; + } + const token = $("newToken").value.trim(); + if (!token) { + out.className = "status bad"; + out.textContent = "paste the import webhook's token"; + return; + } + // asked for straight away, while the click still counts as the user's: browsers only ask from a click + const asked = ext.permissions.request({ origins: [originPattern(server)] }); + (async () => { + if (!(await asked)) { + out.className = "status bad"; + out.textContent = "the clipper needs your permission to talk to that address"; + return; + } + out.className = "status"; + out.textContent = "Checking…"; + const r = await check({ server, token }); + out.className = `status ${r.ok ? "ok" : "bad"}`; + out.textContent = r.message; + if (!r.ok) return; + const id = crypto.randomUUID(); + await settingsStore.setToken(id, token); + const destinations = [...settings.destinations, { id, name: $("newName").value.trim() || new URL(server).host, server }]; + await patch({ destinations, defaultDestination: settings.defaultDestination || id }); + $("newName").value = $("newServer").value = $("newToken").value = ""; + renderDestinations(); + })(); +}); + +// ---------- templates and choices ---------- +const TEXT = ["template", "selectionTemplate", "titleTemplate"]; +const CHECKS = ["readability", "sendImages", "captureOnServer", "reviewQuickClips"]; + +function fill() { + for (const k of TEXT) $(k).value = settings[k] ?? ""; + for (const k of CHECKS) $(k).checked = Boolean(settings[k]); + $("maxImages").value = settings.maxImages; + $("tags").value = (settings.tags ?? []).join(", "); + for (const [k, v] of Object.entries(settings.markdown)) { + const el = $(`md-${k}`); + if (!el) continue; + if (el.type === "checkbox") el.checked = Boolean(v); + else el.value = v; + } +} + +for (const k of TEXT) $(k).addEventListener("change", () => patch({ [k]: $(k).value })); +for (const k of CHECKS) { + $(k).addEventListener("change", () => { + if (k === "sendImages" && $(k).checked) { + ext.permissions.request({ origins: [""] }).then((ok) => { + if (!ok) $(k).checked = false; + patch({ sendImages: ok }); + }); + return; + } + patch({ [k]: $(k).checked }); + }); +} +$("maxImages").addEventListener("change", () => patch({ maxImages: Math.max(1, Math.min(19, Number($("maxImages").value) || 10)) })); +$("tags").addEventListener("change", () => + patch({ + tags: $("tags") + .value.split(",") + .map((t) => t.trim()) + .filter(Boolean), + }), +); +for (const el of document.querySelectorAll("[id^='md-']")) { + el.addEventListener("change", () => { + const key = el.id.slice(3); + patch({ markdown: { ...settings.markdown, [key]: el.type === "checkbox" ? el.checked : el.value } }); + }); +} +$("resetTemplate").addEventListener("click", async () => { + await patch({ template: settingsStore.DEFAULTS.template, selectionTemplate: "", titleTemplate: settingsStore.DEFAULTS.titleTemplate }); + fill(); +}); + +$("vars").replaceChildren( + ...Object.entries(VARIABLES).flatMap(([k, v]) => { + const dt = document.createElement("dt"); + dt.textContent = `{${k}}`; + const dd = document.createElement("dd"); + dd.textContent = v; + return [dt, dd]; + }), +); +$("filters").textContent = `Filters: ${Object.keys(FILTERS).join(", ")}.`; + +(async () => { + settings = await settingsStore.load(); + fill(); + renderDestinations(); +})(); diff --git a/extensions/browser/src/ui/popup.html b/extensions/browser/src/ui/popup.html new file mode 100644 index 000000000..c29fd981f --- /dev/null +++ b/extensions/browser/src/ui/popup.html @@ -0,0 +1,40 @@ + + + + + Lens clipper + + + + +
+

Clip to Lens

+ +
+
+ + + +
+ + + + + + +
+ + + + +
+

+ + + diff --git a/extensions/browser/src/ui/popup.js b/extensions/browser/src/ui/popup.js new file mode 100644 index 000000000..9a7e0ca0a --- /dev/null +++ b/extensions/browser/src/ui/popup.js @@ -0,0 +1,114 @@ +// The popup: clips the tab as soon as it opens (the selection if there is one, else the page), shows the Markdown to +// look over, and sends it. +import * as settingsStore from "../core/settings.js"; +import { itemLink } from "../core/lens.js"; +import { FILTERS } from "../core/template.js"; + +const ext = globalThis.browser ?? globalThis.chrome; +const $ = (id) => document.getElementById(id); +let tab; +let clip; + +function status(text, kind = "") { + $("status").className = `status ${kind}`; + $("status").textContent = text; +} + +function pressed(mode) { + for (const b of document.querySelectorAll(".seg button")) b.setAttribute("aria-pressed", String(b.dataset.mode === mode)); +} + +function show(c) { + clip = c; + $("title").value = c.title; + $("markdown").value = c.markdown; + $("send").disabled = false; + status(c.images?.length ? `${c.images.length} image${c.images.length > 1 ? "s" : ""} in this clip` : ""); +} + +async function run(mode, quiet = false) { + pressed(mode); + if (mode === "pick") { + await ext.runtime.sendMessage({ type: "pick", tabId: tab.id }); + window.close(); // the page needs the pointer; the clip comes back here when it's picked + return; + } + status("Reading the page…"); + const answer = await ext.runtime.sendMessage({ type: "clip", tabId: tab.id, mode }); + if (answer?.ok) return show(answer.clip); + if (quiet) return false; + status(/Cannot access|cannot be scripted|chrome:\/\/|extensions gallery/i.test(answer?.error ?? "") + ? "The browser doesn't let extensions read this page." + : answer?.error ?? "Couldn't read this page", "bad"); +} + +async function destinations() { + const s = await settingsStore.load(); + const sel = $("destination"); + sel.replaceChildren( + ...s.destinations.map((d) => { + const o = document.createElement("option"); + o.value = d.id; + o.textContent = d.name || d.server; + o.selected = d.id === s.defaultDestination; + return o; + }), + ); + if (!s.destinations.length) { + $("send").disabled = true; + status("Add your Lens in Options to send clips. Copy and Download work without it."); + } + return s; +} + +const current = () => ({ ...clip, title: $("title").value.trim() || clip.title, markdown: $("markdown").value }); + +$("send").addEventListener("click", async () => { + if (!clip) return; + $("send").disabled = true; + status("Sending…"); + const answer = await ext.runtime.sendMessage({ type: "send", clip: current(), destination: $("destination").value }); + $("send").disabled = false; + if (!answer?.ok) return status(answer?.error ?? "Couldn't send it", "bad"); + const { server, namespace, items } = answer.answer; + $("status").className = "status ok"; + $("status").replaceChildren(`Sent to ${namespace}. `); + const first = items?.find((i) => i.kind === "text") ?? items?.[0]; + if (first) { + const a = document.createElement("a"); + a.href = itemLink(server, first); + a.target = "_blank"; + a.textContent = "Open in Lens"; + $("status").append(a); + } +}); + +$("copy").addEventListener("click", async () => { + await navigator.clipboard.writeText($("markdown").value); + status("Copied", "ok"); +}); + +$("download").addEventListener("click", () => { + const blob = new Blob([$("markdown").value], { type: "text/markdown" }); + const a = document.createElement("a"); + a.href = URL.createObjectURL(blob); + a.download = `${FILTERS.filename($("title").value) || "clip"}.md`; + a.click(); + setTimeout(() => URL.revokeObjectURL(a.href), 1000); +}); + +$("options").addEventListener("click", () => ext.runtime.openOptionsPage()); +for (const b of document.querySelectorAll(".seg button")) b.addEventListener("click", () => run(b.dataset.mode)); + +(async () => { + [tab] = await ext.tabs.query({ active: true, currentWindow: true }); + await destinations(); + await ext.action.setBadgeText({ tabId: tab.id, text: "" }); + const { pending } = await ext.storage.session.get("pending"); + if (pending && pending.tabId === tab.id && Date.now() - pending.at < 30 * 60 * 1000) { + await ext.storage.session.remove("pending"); + pressed("pick"); + return show(pending.clip); + } + if ((await run("selection", true)) === false) await run("page"); +})(); diff --git a/extensions/browser/src/ui/style.css b/extensions/browser/src/ui/style.css new file mode 100644 index 000000000..250ce18d0 --- /dev/null +++ b/extensions/browser/src/ui/style.css @@ -0,0 +1,64 @@ +:root { + color-scheme: light dark; + --bg: #ffffff; + --fg: #16161d; + --muted: #5d5d6b; + --line: #dedee6; + --field: #f6f6f9; + --accent: #6d5dfc; + --accent-fg: #ffffff; + --ok: #15803d; + --bad: #b91c1c; + font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; +} +@media (prefers-color-scheme: dark) { + :root { + --bg: #17171d; + --fg: #ececf1; + --muted: #a1a1b0; + --line: #33333d; + --field: #202029; + --accent: #8b7dff; + --ok: #4ade80; + --bad: #f87171; + } +} +* { box-sizing: border-box; } +body { margin: 0; background: var(--bg); color: var(--fg); } +h1 { font-size: 15px; margin: 0; display: flex; align-items: center; gap: 8px; } +h1 img { width: 20px; height: 20px; } +h2 { font-size: 14px; margin: 24px 0 8px; } +label { display: block; font-size: 13px; font-weight: 500; margin: 10px 0 4px; } +.hint { color: var(--muted); font-size: 12px; font-weight: 400; } +input[type="text"], input[type="url"], input[type="password"], input[type="number"], select, textarea { + width: 100%; + font: inherit; + color: inherit; + background: var(--field); + border: 1px solid var(--line); + border-radius: 6px; + padding: 6px 8px; +} +textarea { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; resize: vertical; } +button { + font: inherit; + border: 1px solid var(--line); + background: var(--field); + color: inherit; + border-radius: 6px; + padding: 6px 12px; + cursor: pointer; +} +button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; } +button:disabled { opacity: 0.55; cursor: default; } +.row { display: flex; gap: 8px; align-items: center; } +.row > .grow { flex: 1; } +.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; } +.seg button { border: 0; border-radius: 0; flex: 1; background: transparent; } +.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); } +.status { min-height: 18px; font-size: 12px; color: var(--muted); } +.status.ok { color: var(--ok); } +.status.bad { color: var(--bad); } +a { color: var(--accent); } +.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; } +.check input { margin-top: 3px; } diff --git a/extensions/browser/targets/chrome.json b/extensions/browser/targets/chrome.json new file mode 100644 index 000000000..88c5d9e09 --- /dev/null +++ b/extensions/browser/targets/chrome.json @@ -0,0 +1,3 @@ +{ + "minimum_chrome_version": "116" +} diff --git a/extensions/browser/test/clip.test.js b/extensions/browser/test/clip.test.js new file mode 100644 index 000000000..8784e30d8 --- /dev/null +++ b/extensions/browser/test/clip.test.js @@ -0,0 +1,82 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { clip } from "../src/core/clip.js"; +import { extractMetadata } from "../src/core/metadata.js"; +import { DEFAULTS } from "../src/core/settings.js"; +import { page } from "./fixtures.js"; + +const settings = structuredClone(DEFAULTS); +const now = new Date("2026-10-10T12:00:00Z"); + +test("metadata from meta tags", () => { + const m = extractMetadata(page()); + assert.equal(m.title, "How Lenses Work"); + assert.equal(m.url, "https://example.com/articles/lenses"); + assert.equal(m.domain, "example.com"); + assert.equal(m.siteName, "Example Science"); + assert.equal(m.byline, "Ada Lovelace"); + assert.equal(m.published, "2026-03-04T10:00:00.000Z"); + assert.equal(m.image, "https://example.com/img/lead.jpg"); + assert.deepEqual(m.keywords, ["optics", "lenses"]); + assert.equal(m.lang, "en"); +}); + +test("metadata from JSON-LD", () => { + const doc = page(``); + const m = extractMetadata(doc); + assert.equal(m.title, "LD headline"); + assert.equal(m.byline, "Grace"); + assert.equal(m.image, "https://cdn.example/i.png"); +}); + +test("a full page becomes its article, with front matter", () => { + const c = clip(page(), { mode: "page", settings, tags: ["reading"], now }); + assert.equal(c.title, "How Lenses Work"); + assert.equal(c.clipType, "page"); + assert.match(c.markdown, /^---\ntitle: How Lenses Work\nsource: https:\/\/example.com\/articles\/lenses\nauthor: Ada Lovelace\n/); + assert.match(c.markdown, /published: 2026-03-04\n/); + assert.match(c.markdown, /tags: \["reading"\]/); + assert.match(c.markdown, /\[the glossary\]\(https:\/\/example.com\/glossary#focal\)/); + assert.match(c.markdown, /!\[A ray diagram\]\(https:\/\/example.com\/img\/diagram.png\)/); + assert.match(c.markdown, /```python\nprint\("focus"\)\n```/); + assert.match(c.markdown, /\| Lens \| Focal \|/); + assert.doesNotMatch(c.markdown, /javascript:|window.evil|Copyright footer|About\]/); + assert.deepEqual(c.images, ["https://example.com/img/diagram.png"]); +}); + +test("without Readability the whole body is kept", () => { + const c = clip(page(), { mode: "page", settings: { ...settings, readability: false }, now }); + assert.match(c.markdown, /Copyright footer/); +}); + +test("a picked element, with the selection template", () => { + const doc = page(); + const c = clip(doc, { + mode: "element", + element: doc.querySelector("table"), + settings: { ...settings, selectionTemplate: "> from {domain}\n\n{content}" }, + now, + }); + assert.equal(c.markdown, "> from example.com\n\n| Lens | Focal |\n| --- | --- |\n| A | 50mm |\n"); +}); + +test("the selection", () => { + const doc = page(); + const range = doc.createRange(); + range.selectNodeContents(doc.querySelector("article p")); + doc.getSelection().addRange(range); + const c = clip(doc, { mode: "selection", settings: { ...settings, selectionTemplate: "{content}" }, now }); + assert.match(c.markdown, /^A lens bends light\./); +}); + +test("no selection is an error the popup can show", () => { + assert.throws(() => clip(page(), { mode: "selection", settings, now }), /Select some text/); +}); + +test("markdown options apply", () => { + const md = { ...settings.markdown, images: "drop", links: "text", bulletListMarker: "*" }; + const doc = page(``); + const c = clip(doc, { mode: "element", element: doc.body, settings: { ...settings, markdown: md, selectionTemplate: "{content}" }, now }); + assert.equal(c.markdown, "* one\n"); +}); diff --git a/extensions/browser/test/fixtures.js b/extensions/browser/test/fixtures.js new file mode 100644 index 000000000..dfd2cc32d --- /dev/null +++ b/extensions/browser/test/fixtures.js @@ -0,0 +1,33 @@ +import { JSDOM } from "jsdom"; + +export const ARTICLE = ` +Fallback title | Example + + + + + + + + + + +
+

How Lenses Work

+

A lens bends light. This paragraph is long enough for Readability to think it is the article body, which it needs +to be, so here is some more text about refraction, focal lengths and the way glass slows light down as it passes.

+

See the glossary for terms, and the bad link.

+A ray diagram +
print("focus")
+
+
LensFocal
A50mm
+

Another paragraph with emphasis and strength, again long enough to count as content for +the extraction step that keeps articles and drops the rest of the page.

+ +
+
Copyright footer
+`; + +export function page(html = ARTICLE, url = "https://example.com/articles/lenses?ref=x") { + return new JSDOM(html, { url }).window.document; +} diff --git a/extensions/browser/test/lens.test.js b/extensions/browser/test/lens.test.js new file mode 100644 index 000000000..bc7c769c0 --- /dev/null +++ b/extensions/browser/test/lens.test.js @@ -0,0 +1,63 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { check, fetchImages, push } from "../src/core/lens.js"; +import { normalizeServer } from "../src/core/settings.js"; + +const reply = (status, body = {}, type = "application/json") => new Response(JSON.stringify(body), { status, headers: { "content-type": type } }); + +test("a plain clip goes as JSON text with the bearer token", async () => { + let seen; + const fetchImpl = async (url, init) => { + seen = { url, init }; + return reply(202, { namespace: "home", items: [{ kind: "text", name: "T", recording: 7 }] }); + }; + const out = await push({ server: "https://lens.test", token: "lih_abc" }, { title: "T", markdown: "# T", url: "https://x" }, { fetchImpl }); + assert.equal(seen.url, "https://lens.test/api/v1/hooks/import"); + assert.equal(seen.init.headers.Authorization, "Bearer lih_abc"); + assert.deepEqual(JSON.parse(seen.init.body), { text: "# T", title: "T" }); + assert.equal(out.items[0].recording, 7); +}); + +test("images and server capture go as multipart", async () => { + let body; + const fetchImpl = async (_url, init) => { + body = init.body; + return reply(202, { namespace: "home", items: [] }); + }; + const images = [{ name: "a.png", blob: new Blob(["x"], { type: "image/png" }) }]; + await push({ server: "https://lens.test", token: "t" }, { title: "T", markdown: "m", url: "https://x.test/p" }, { images, captureUrl: true, fetchImpl }); + assert.ok(body instanceof FormData); + assert.equal(body.get("text"), "m"); + assert.equal(body.get("url"), "https://x.test/p"); + assert.equal(body.getAll("file").length, 1); +}); + +test("errors say what to do", async () => { + const fetchImpl = async () => reply(401, { detail: "unknown" }); + await assert.rejects(push({ server: "https://l", token: "t" }, { title: "T", markdown: "m" }, { fetchImpl }), /didn't recognise this token/); + await assert.rejects(push({ server: "https://l", token: "" }, { title: "T", markdown: "m" }, { fetchImpl }), /token/); +}); + +test("check reads 400 as a known token", async () => { + assert.equal((await check({ server: "https://l", token: "t" }, { fetchImpl: async () => reply(400, { detail: "send a url" }) })).ok, true); + assert.equal((await check({ server: "https://l", token: "t" }, { fetchImpl: async () => reply(401) })).ok, false); + assert.match((await check({ server: "https://l", token: "t" }, { fetchImpl: async () => reply(404) })).message, /not as a Lens/); +}); + +test("images: only real images, named sensibly, failures skipped", async () => { + const fetchImpl = async (url) => { + if (url.includes("fail")) throw new Error("network"); + if (url.includes("html")) return new Response("

", { headers: { "content-type": "text/html" } }); + return new Response(new Blob(["x"], { type: "image/webp" })); + }; + const out = await fetchImages(["https://a/x/photo.jpg?w=1", "https://a/fail.png", "https://a/page.html", "https://a/raw"], { fetchImpl }); + assert.deepEqual(out.map((i) => i.name), ["photo.jpg", "image-4.webp"]); +}); + +test("server addresses", () => { + assert.equal(normalizeServer("lens.example.com/"), "https://lens.example.com"); + assert.equal(normalizeServer("http://localhost:3000"), "http://localhost:3000"); + assert.equal(normalizeServer("http://192.168.1.5/lens/"), "http://192.168.1.5/lens"); + assert.throws(() => normalizeServer("http://lens.example.com"), /https/); + assert.throws(() => normalizeServer("http://localhost.evil.com"), /https/); +}); diff --git a/extensions/browser/test/template.test.js b/extensions/browser/test/template.test.js new file mode 100644 index 000000000..a3236f00c --- /dev/null +++ b/extensions/browser/test/template.test.js @@ -0,0 +1,34 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { formatDate, render } from "../src/core/template.js"; + +test("variables, filters and literal braces", () => { + const out = render("{title|kebab} {{x}} {missing} {tags:, } {title|upper}", { title: "Hello World", tags: ["a", "b"] }); + assert.equal(out, "hello-world {x} a, b HELLO WORLD"); +}); + +test("dates take a format", () => { + const d = new Date(2026, 0, 5, 7, 8, 9); + assert.equal(formatDate(d, "YYYY-MM-DD HH:mm:ss"), "2026-01-05 07:08:09"); + assert.equal(render("{date:D/M/YY}", { date: d }), "5/1/26"); + assert.equal(render("{published:YYYY}", { published: "" }), ""); +}); + +test("empty front matter fields are dropped, lists kept", () => { + const out = render("---\ntitle: {title|yaml}\nauthor: {byline|yaml}\ntags: {tags|list}\nlist:\n - one\n---\n\nbody", { + title: "A: B", + byline: "", + tags: ["x"], + }); + assert.equal(out, '---\ntitle: "A: B"\ntags: ["x"]\nlist:\n - one\n---\n\nbody'); +}); + +test("yaml filter quotes only what needs it", () => { + assert.equal(render("{v|yaml}", { v: "Plain title" }), "Plain title"); + assert.equal(render("{v|yaml}", { v: "yes" }), '"yes"'); + assert.equal(render("{v|yaml}", { v: '#tag "q"' }), '"#tag \\"q\\""'); +}); + +test("filename filter", () => { + assert.equal(render("{t|filename}", { t: 'a/b:c*"d"' }), "a b c d"); +}); diff --git a/mkdocs.yml b/mkdocs.yml index d1f90077a..f1904d7d4 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -86,6 +86,7 @@ nav: - Graph history: graph-history.md - Topics: topics.md - Notes: notes.md + - Web clipper: web-clipper.md - Storage: storage.md - Linked data (RDF): rdf.md - Fedora repository: fedora.md From 073fa320ddfef75dde4ef2ec6a23ff91ba794f96 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sat, 10 Oct 2026 20:08:50 +0000 Subject: [PATCH 2/2] feat(clipper): Edge build, Edge Add-ons package and an Edge smoke test in CI Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01JdVNcZL5BUSx3iwStCtq3U --- .github/workflows/clipper-edge.yml | 49 ++++++++ extensions/browser/edge/README.md | 28 +++++ extensions/browser/edge/package-lock.json | 29 +++++ extensions/browser/edge/package.json | 14 +++ extensions/browser/edge/smoke.mjs | 130 ++++++++++++++++++++++ extensions/browser/targets/edge.json | 3 + 6 files changed, 253 insertions(+) create mode 100644 .github/workflows/clipper-edge.yml create mode 100644 extensions/browser/edge/README.md create mode 100644 extensions/browser/edge/package-lock.json create mode 100644 extensions/browser/edge/package.json create mode 100644 extensions/browser/edge/smoke.mjs create mode 100644 extensions/browser/targets/edge.json diff --git a/.github/workflows/clipper-edge.yml b/.github/workflows/clipper-edge.yml new file mode 100644 index 000000000..c9d0e5912 --- /dev/null +++ b/.github/workflows/clipper-edge.yml @@ -0,0 +1,49 @@ +name: Web clipper (Edge) + +# Loads the Edge build of the web clipper (extensions/browser/targets/edge.json) into Microsoft Edge and clips a page +# into a stand-in Lens (extensions/browser/edge/smoke.mjs). The Edge zip itself, lens-clipper-edge.zip, comes from the +# Browser extension workflow with the other browsers'. +on: + push: + branches: [main] + paths: + - extensions/browser/** + - .github/workflows/clipper-edge.yml + pull_request: + paths: + - extensions/browser/** + - .github/workflows/clipper-edge.yml + workflow_dispatch: + +permissions: + contents: read + +jobs: + edge: + name: Clip a page in Edge + runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }} + defaults: + run: + working-directory: ./extensions/browser + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v7 + with: + node-version: "22" + cache: npm + cache-dependency-path: | + extensions/browser/package-lock.json + extensions/browser/edge/package-lock.json + - run: npm ci + - run: npm run build -- --target edge + - run: npm ci + working-directory: ./extensions/browser/edge + - name: Install Edge and a display if the runner lacks them + working-directory: ./extensions/browser/edge + run: | + if [ -x /opt/microsoft/msedge/msedge ]; then /opt/microsoft/msedge/msedge --version + else npx playwright-core install --with-deps msedge; fi + command -v xvfb-run || (sudo apt-get update && sudo apt-get install -y xvfb) + - name: Smoke test in Edge + working-directory: ./extensions/browser/edge + run: xvfb-run -a npm run smoke diff --git a/extensions/browser/edge/README.md b/extensions/browser/edge/README.md new file mode 100644 index 000000000..6b8acebe9 --- /dev/null +++ b/extensions/browser/edge/README.md @@ -0,0 +1,28 @@ +# The web clipper in Microsoft Edge + +Edge runs the Chrome build's code; `../targets/edge.json` is its manifest (Edge reads `minimum_chrome_version` as +its own minimum, and Edge 116 is the first with everything the clipper uses). + +```sh +cd extensions/browser && npm ci && npm run build -- --target edge +``` + +- **Try it**: open `edge://extensions`, turn on **Developer mode**, **Load unpacked**, and pick `dist/edge`. +- **Install a release**: every release has `lens-clipper-edge.zip` attached (and every CI run keeps it as an + artifact). Unzip it and load the folder the same way. +- **Edge Add-ons**: `lens-clipper-edge.zip` is the package to upload in Partner Center + (). The listing's privacy policy answer: the clipper sends + what you clip only to the Lens you add, and keeps its token on this device. + +## Smoke test + +`smoke.mjs` loads `dist/edge` into Edge, checks the options page and the popup render, then clips an article page and +checks a stand-in Lens import webhook gets the Markdown with the hook's token. CI runs it in +`.github/workflows/clipper-edge.yml`. + +```sh +cd edge && npm ci && npx playwright-core install msedge # once, if Edge isn't installed +xvfb-run -a npm run smoke # or just `npm run smoke` on a desktop +``` + +`EDGE_CHANNEL=chromium CHROMIUM_PATH=/path/to/chrome npm run smoke` runs the same test in Chromium. diff --git a/extensions/browser/edge/package-lock.json b/extensions/browser/edge/package-lock.json new file mode 100644 index 000000000..bf14cee46 --- /dev/null +++ b/extensions/browser/edge/package-lock.json @@ -0,0 +1,29 @@ +{ + "name": "lens-web-clipper-edge-smoke", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "lens-web-clipper-edge-smoke", + "version": "0.0.0", + "license": "MIT", + "devDependencies": { + "playwright-core": "1.63.0" + } + }, + "node_modules/playwright-core": { + "version": "1.63.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.63.0.tgz", + "integrity": "sha512-rYCsBF/M5HjUch52bbtVONEFjv6Xu8sm8h72dNlR5bzIE1fvC/bxgspzkjSfU+MweEMmPM8KJebG6nnyxo5mCg==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + } + } +} diff --git a/extensions/browser/edge/package.json b/extensions/browser/edge/package.json new file mode 100644 index 000000000..0e7de1235 --- /dev/null +++ b/extensions/browser/edge/package.json @@ -0,0 +1,14 @@ +{ + "name": "lens-web-clipper-edge-smoke", + "version": "0.0.0", + "private": true, + "description": "Loads the Edge build of the Lens web clipper in Microsoft Edge and clips a page into a stand-in Lens", + "license": "MIT", + "type": "module", + "scripts": { + "smoke": "node smoke.mjs" + }, + "devDependencies": { + "playwright-core": "1.63.0" + } +} diff --git a/extensions/browser/edge/smoke.mjs b/extensions/browser/edge/smoke.mjs new file mode 100644 index 000000000..fa383667c --- /dev/null +++ b/extensions/browser/edge/smoke.mjs @@ -0,0 +1,130 @@ +// Edge smoke test: loads dist/edge (npm run build in ..) into Microsoft Edge, opens the popup and options, clips an +// article page and checks a stand-in Lens import webhook got its Markdown. Run under a display (xvfb-run in CI). +// EDGE_CHANNEL=chromium runs the same test in Playwright's Chromium, for machines without Edge. +import { cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { createServer } from "node:http"; +import { tmpdir } from "node:os"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { chromium } from "playwright-core"; + +const here = dirname(fileURLToPath(import.meta.url)); +const built = join(here, "..", "dist", "edge"); +const TOKEN = "lih_edge-smoke-token"; + +const ARTICLE = ` +Edge smoke article + + + +

Clipping from Edge

+${"

The Lens clipper turns what you read into Markdown with its metadata and images, so it can be filed and found again later.

".repeat(6)} +
  • first point
  • second point
const x = 1;
+
`; + +// the article page and a stand-in for Lens's import webhook, on one local port +const pushes = []; +const server = createServer((req, res) => { + const cors = { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Headers": "Authorization, Content-Type, Accept", + "Access-Control-Allow-Methods": "POST, OPTIONS", + }; + if (req.method === "OPTIONS") return res.writeHead(204, cors).end(); + if (req.url === "/article") return res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }).end(ARTICLE); + if (req.url === "/api/v1/hooks/import" && req.method === "POST") { + let body = ""; + req.on("data", (c) => (body += c)); + req.on("end", () => { + pushes.push({ auth: req.headers.authorization, type: req.headers["content-type"], body }); + res.writeHead(200, { ...cors, "Content-Type": "application/json" }); + res.end(JSON.stringify({ namespace: "smoke", items: [{ kind: "text", name: "clip", recording: "r1" }] })); + }); + return; + } + res.writeHead(404, cors).end(); +}); +await new Promise((ok) => server.listen(0, "127.0.0.1", ok)); +const origin = `http://127.0.0.1:${server.address().port}`; + +// The real build only reaches a tab through activeTab, which a click grants and a test can't. This copy also holds +// host permission for the test server; everything else is dist/edge as shipped. +const ext = mkdtempSync(join(tmpdir(), "lens-clipper-edge-")); +cpSync(built, ext, { recursive: true }); +const manifest = JSON.parse(readFileSync(join(ext, "manifest.json"), "utf8")); +writeFileSync(join(ext, "manifest.json"), JSON.stringify({ ...manifest, host_permissions: ["http://127.0.0.1/*"] })); + +const profile = mkdtempSync(join(tmpdir(), "lens-edge-profile-")); +const channel = process.env.EDGE_CHANNEL || "msedge"; +const context = await chromium.launchPersistentContext(profile, { + channel: channel === "chromium" ? undefined : channel, + executablePath: channel === "chromium" ? process.env.CHROMIUM_PATH : undefined, + headless: false, + args: [`--disable-extensions-except=${ext}`, `--load-extension=${ext}`, "--no-first-run"], +}); + +const failures = []; +const check = (ok, what) => { + console.log(`${ok ? "ok " : "FAIL"} ${what}`); + if (!ok) failures.push(what); +}; + +try { + const browserVersion = context.browser()?.version() ?? ""; + const worker = context.serviceWorkers()[0] ?? (await context.waitForEvent("serviceworker", { timeout: 15000 })); + const id = new URL(worker.url()).host; + console.log(`${channel} ${browserVersion}: extension ${id} loaded (${manifest.name} ${manifest.version})`); + check(manifest.manifest_version === 3 && manifest.minimum_chrome_version, "the Edge manifest is MV3 with a minimum version"); + + // a first install opens the options page; it and the popup render without errors + const errors = []; + for (const page of ["options.html", "popup.html"]) { + const p = await context.newPage(); + p.on("pageerror", (e) => errors.push(`${page}: ${e.message}`)); + await p.goto(`chrome-extension://${id}/${page}`); + await p.waitForLoadState("load"); + check((await p.locator("body").innerText()).trim().length > 0, `${page} renders`); + await p.close(); + } + + // a destination, as the options page saves one + await worker.evaluate( + async ({ server, token }) => { + await chrome.storage.sync.set({ destinations: [{ id: "d1", name: "Smoke", server }], defaultDestination: "d1" }); + await chrome.storage.local.set({ "token:d1": token }); + }, + { server: origin, token: TOKEN }, + ); + + // clip the article and send it, the way the popup does: a "clip" message, then a "send" one + const article = await context.newPage(); + await article.goto(`${origin}/article`); + const page = await context.newPage(); + await page.goto(`chrome-extension://${id}/options.html`); + const tabId = await page.evaluate(async (url) => (await chrome.tabs.query({ url })).at(0)?.id, `${origin}/article`); + const clipped = await page.evaluate((tabId) => chrome.runtime.sendMessage({ type: "clip", tabId, mode: "page" }), tabId); + check(clipped?.ok, `the page clips${clipped?.ok ? "" : `: ${clipped?.error}`}`); + const md = clipped?.clip?.markdown ?? ""; + if (process.env.SMOKE_DEBUG) console.log(md); + check(/^title: "?Clipping from Edge"?$/m.test(md), "the clip's front matter has the title"); + check(/^author: "?Ada Lovelace"?$/m.test(md), "and the author"); + check(/^-\s+second point$/m.test(md) && md.includes("```js"), "the article's list and code block are Markdown"); + check(!md.includes("footer links"), "Readability left the footer out"); + + const sent = await page.evaluate((clip) => chrome.runtime.sendMessage({ type: "send", clip }), clipped?.clip); + check(sent?.ok && sent.answer?.namespace === "smoke", `the clip is sent${sent?.ok ? "" : `: ${sent?.error}`}`); + const push = pushes.at(-1); + check(push?.auth === `Bearer ${TOKEN}`, "Lens got it with the hook's token"); + check(push && JSON.parse(push.body).text === md, "and the Markdown as text"); +} finally { + await context.close(); + server.close(); + rmSync(ext, { recursive: true, force: true }); + rmSync(profile, { recursive: true, force: true }); +} + +if (failures.length) { + console.error(`\n${failures.length} check(s) failed`); + process.exit(1); +} +console.log("\nEdge smoke test passed"); diff --git a/extensions/browser/targets/edge.json b/extensions/browser/targets/edge.json new file mode 100644 index 000000000..88c5d9e09 --- /dev/null +++ b/extensions/browser/targets/edge.json @@ -0,0 +1,3 @@ +{ + "minimum_chrome_version": "116" +}