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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/browser-extension-firefox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Browser extension (Firefox)

# The Firefox build of the Lens web clipper (extensions/browser, target firefox): Mozilla's own linter (web-ext lint,
# the checks addons.mozilla.org runs) on dist/firefox, then web-ext build for an upload-ready zip. A release also gets
# it signed by Mozilla (unlisted, so it installs from the release page, and updates itself through the
# lens-clipper-firefox-updates.json the Browser extension workflow attaches) as lens-clipper-firefox.xpi when the
# AMO_JWT_ISSUER and AMO_JWT_SECRET secrets hold an addons.mozilla.org API key; the unsigned zip reaches the release
# through the Browser extension workflow either way.
on:
push:
branches: [main]
paths:
- extensions/browser/**
- .github/workflows/browser-extension-firefox.yml
pull_request:
paths:
- extensions/browser/**
- .github/workflows/browser-extension-firefox.yml
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Release tag to attach the Firefox build to; blank: build this ref"
default: ""

permissions:
contents: read

env:
WEB_EXT: web-ext@10.7.0
AMO_JWT_ISSUER: ${{ secrets.AMO_JWT_ISSUER }}
AMO_JWT_SECRET: ${{ secrets.AMO_JWT_SECRET }}

jobs:
firefox:
name: Lint and package the Firefox clipper
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
permissions:
contents: write # to attach the build 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
- name: Build the Firefox target
env:
EXT_VERSION: ${{ github.event.release.tag_name || inputs.tag }}
run: npm run check -- --target firefox
- name: web-ext lint (fails on errors; warnings are listed)
run: npx --yes "$WEB_EXT" lint --source-dir dist/firefox
- name: web-ext build
run: npx --yes "$WEB_EXT" build --source-dir dist/firefox --artifacts-dir ../../dist/firefox --filename lens-clipper-firefox.zip --overwrite-dest
- name: Sign for self-distribution
if: (github.event_name == 'release' || inputs.tag != '') && env.AMO_JWT_ISSUER != ''
env:
EXT_VERSION: ${{ github.event.release.tag_name || inputs.tag }}
EXT_UPDATE_BASE: ${{ github.server_url }}/${{ github.repository }}/releases/latest/download
run: |
# the self-hosted copy carries an update_url, so the signed .xpi updates itself from the newest release
npm run build -- --target firefox
npx --yes "$WEB_EXT" sign --source-dir dist/firefox-selfhosted --artifacts-dir ../../dist/firefox/signed \
--channel unlisted --api-key "$AMO_JWT_ISSUER" --api-secret "$AMO_JWT_SECRET"
for f in ../../dist/firefox/signed/*.xpi; do mv "$f" ../../dist/firefox/lens-clipper-firefox.xpi; done
- uses: actions/upload-artifact@v7
with:
name: lens-clipper-firefox
path: dist/firefox/lens-clipper-firefox.*
- name: Attach the signed build to the release
if: (github.event_name == 'release' || inputs.tag != '') && env.AMO_JWT_ISSUER != ''
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.release.tag_name || inputs.tag }}
run: gh release upload "$TAG" ../../dist/firefox/lens-clipper-firefox.xpi --clobber --repo "${{ github.repository }}"
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 browser-extension.yml safari-clipper.yml; do
for workflow in cloudron.yml qnap.yml synology.yml launchers.yml browser-extension.yml safari-clipper.yml browser-extension-firefox.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
Expand Down
16 changes: 15 additions & 1 deletion docs/web-clipper.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Web clipper

**Status: built (Chrome and Edge); Firefox and Safari in progress.** Every browser's build comes from the same code;
**Status: built (Chrome, Edge and Firefox); Safari in progress.** Every browser's build comes 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,
Expand Down Expand Up @@ -108,6 +108,20 @@ A target is `extensions/browser/targets/<name>.json`, merged over `src/manifest.
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`.

### Firefox

Firefox 128 or later (desktop). `targets/firefox.json` runs the background as a script instead of a service worker
and gives the add-on its id, `lens-clipper@adeelahmad.github.io`. To try a build, open `about:debugging`, choose
**This Firefox**, then **Load Temporary Add-on…** and pick `dist/firefox/manifest.json`; it stays until Firefox
restarts.

The Browser extension (Firefox) workflow runs Mozilla's linter, `web-ext lint` (the checks addons.mozilla.org runs),
on every pull request that changes the clipper, and keeps `lens-clipper-firefox.zip` (ready to upload to
addons.mozilla.org) with the run. On a release, if the `AMO_JWT_ISSUER` and `AMO_JWT_SECRET` secrets hold an
[addons.mozilla.org API key](https://addons.mozilla.org/developers/addon/api/key/), Mozilla signs it as an unlisted
add-on and the release gets `lens-clipper-firefox.xpi`, which any Firefox installs by opening it. That copy is built
from `dist/firefox-selfhosted`, so it updates itself from the newest release (see below).

## Releases and updates

Every Lens release builds the clipper for each browser and attaches `lens-clipper-<browser>.zip` to it. How a copy
Expand Down
10 changes: 10 additions & 0 deletions extensions/browser/targets/firefox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"background": { "service_worker": null, "scripts": ["background.js"] },
"browser_specific_settings": {
"gecko": {
"id": "lens-clipper@adeelahmad.github.io",
"strict_min_version": "128.0",
"data_collection_permissions": { "required": ["none"] }
}
}
}
Loading