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
49 changes: 49 additions & 0 deletions .github/workflows/clipper-edge.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions extensions/browser/edge/README.md
Original file line number Diff line number Diff line change
@@ -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
(<https://partner.microsoft.com/dashboard/microsoftedge>). 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.
29 changes: 29 additions & 0 deletions extensions/browser/edge/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions extensions/browser/edge/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
130 changes: 130 additions & 0 deletions extensions/browser/edge/smoke.mjs
Original file line number Diff line number Diff line change
@@ -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 = `<!doctype html><html lang="en"><head>
<title>Edge smoke article</title>
<meta property="og:title" content="Clipping from Edge">
<meta name="author" content="Ada Lovelace">
<meta property="og:site_name" content="Smoke Times">
</head><body><nav>Home · About</nav><article><h1>Clipping from Edge</h1>
${"<p>The Lens clipper turns what you read into Markdown with its metadata and images, so it can be filed and found again later.</p>".repeat(6)}
<ul><li>first point</li><li>second point</li></ul><pre><code class="language-js">const x = 1;</code></pre>
</article><footer>footer links</footer></body></html>`;

// 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");
3 changes: 3 additions & 0 deletions extensions/browser/targets/edge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"minimum_chrome_version": "116"
}
Loading