Compare commits

..
5 Commits
Author SHA1 Message Date
Knotty Wyvern 5c4d759c1b Pin browser engine 0.1.11
Engine 0.1.11 finds the link under a middle-click. It replaces engine 0.1.10 in the pin.
2026-10-31 19:42:17 -07:00
Knotty Wyvern 2ca7752c9d Open links and images in new browser tabs
- A middle-click on a link opens the link in a new tab. Scrolling
  starts at once, as before. The new engine command linkAt reads the
  link under the pointer in an isolated world. When it finds a web
  link, the tab stops the scroll and opens the link.
- The image menu of a page starts with Open image in new tab.

A new tab opens in front, like Open link in new tab. The engine smoke
test checks linkAt, and the interaction test checks both actions with
the real engine. Cards 333909d1 and f7ee842d.
2026-10-31 19:41:27 -07:00
Knotty Wyvern 68c302a271 Pin browser engine 0.1.10
Engine 0.1.10 keeps the display scale when a page replaces itself during its load. It replaces engine 0.1.9 in the pin.
2026-10-31 19:08:13 -07:00
Knotty Wyvern 19ef8f2e15 Keep the display scale when a page replaces itself during its load
The engine applied device emulation at did-finish-load. Each new
document gets a renderer widget without emulation. Google replaces its
first document with ?zx=... before that document finishes. Thus the
first document kept a scale of 1, and the page grew by the display
scale when the second document finished.

The engine now also applies emulation when a main-frame document
commits. In the real app at 125%, Google keeps the same size before and
after its second document. Card 40a8db13.
2026-10-31 19:06:45 -07:00
Knotty Wyvern 28661f28bc Draw the browser scroll marker with the scroll icon
Middle-click scrolling in the built-in browser showed the text arrow
"↕" at 20 px in a 24 px circle. The look of that glyph depends on the
font, and the circle cut it. It also showed only two directions, but
the scroll moves in four.

The marker now uses the four-way scroll icon of Project Management,
which the shared Icon component also gets. The marker has the size of
the Project Management marker: a 26 px circle with a 20 px icon. The
interaction smoke test checks the icon and keeps screenshots in both
themes. Card ac49c9ec.
2026-10-31 19:06:45 -07:00
12 changed files with 88 additions and 15 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "runestone-browser",
"version": "0.1.9",
"version": "0.1.11",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "runestone-browser",
"version": "0.1.9",
"version": "0.1.11",
"dependencies": {
"@ghostery/adblocker": "2.18.2",
"ipaddr.js": "2.3.0"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "runestone-browser",
"version": "0.1.9",
"version": "0.1.11",
"private": true,
"description": "Isolated browser runtime included with RuneStone",
"type": "module",
+11 -1
View File
@@ -166,7 +166,9 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
changed();
}
});
wc.on('did-navigate', (_event, url) => { store.visit(profileId, url, item.title); changed(); });
// Each new document gets a renderer widget without device emulation. A page that replaces itself before it finishes
// loading, as Google does, otherwise keeps a scale of 1 and grows when the next document finishes.
wc.on('did-navigate', (_event, url) => { emulateViewport(item); store.visit(profileId, url, item.title); changed(); });
wc.on('did-navigate-in-page', (_event, _url, main) => { if (main) { item.epoch++; agent.revokeAll(); } changed(); });
wc.on('page-title-updated', (_event, title) => { item.title = title.slice(0, 200); changed(); });
wc.on('page-favicon-updated', (_event, urls) => {
@@ -290,6 +292,14 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
}
return null;
}
case 'linkAt': {
// A middle-click on a link opens it in a new tab. The isolated world keeps page scripts from changing the answer.
if (![args.x, args.y].every(value => Number.isInteger(value) && value >= 0 && value <= 5120)) throw new Error('Invalid pointer position.');
const href = await tab(args.tabId).view.webContents.executeJavaScriptInIsolatedWorld(902, [{
code: `document.elementFromPoint(${args.x}, ${args.y})?.closest('a[href], area[href]')?.href ?? ''`,
}]).catch(() => '');
try { return { url: href ? webUrl(href, { blank: false }) : null }; } catch { return { url: null }; }
}
case 'copiedImage': {
// A part stays below the line limit of the host connection.
if (!copied || copied.token !== args.token || copied.tabId !== args.tabId || !Number.isSafeInteger(args.offset) || args.offset < 0 || args.offset >= copied.data.length) {
+8
View File
@@ -161,6 +161,13 @@ app.whenReady().then(async () => {
assert.equal(whole.subarray(0, 6).toString(), 'GIF89a');
assert.equal(whole.at(-1), 0x3b);
await wc.executeJavaScript('document.querySelector("#copy-image").remove();true;');
// A middle-click asks for the link under the pointer. Only web links count.
await wc.executeJavaScript(`document.body.insertAdjacentHTML('beforeend', '<a id="middle-link" href="${process.env.RS_TEST_URL}linked" style="position:absolute;left:600px;top:40px;width:120px;height:30px;display:block">Linked</a><a id="script-link" href="javascript:void(0)" style="position:absolute;left:600px;top:100px;width:120px;height:30px;display:block">Script</a>');true;`);
assert.deepEqual(await engine.command('linkAt', { tabId: first, x: 650, y: 50 }), { url: `${process.env.RS_TEST_URL}linked` });
assert.deepEqual(await engine.command('linkAt', { tabId: first, x: 650, y: 110 }), { url: null });
assert.deepEqual(await engine.command('linkAt', { tabId: first, x: 900, y: 600 }), { url: null });
await assert.rejects(engine.command('linkAt', { tabId: first, x: -1, y: 50 }), /Invalid pointer position/);
await wc.executeJavaScript('document.querySelector("#middle-link").remove(); document.querySelector("#script-link").remove();true;');
// An image that opens as the page itself is the main resource of the tab.
const direct = (await engine.command('newTab', { url: `${process.env.RS_TEST_URL}direct.gif` })).tabId;
const directContents = engine.tabs.get(direct).view.webContents;
@@ -174,6 +181,7 @@ app.whenReady().then(async () => {
assert.deepEqual([directCopy.mime, directCopy.size], ['image/gif', large.size]);
await engine.command('closeTab', { tabId: direct });
passed.push('Copy image keeps the loaded GIF bytes without a second request, also for an image that opens as the page');
passed.push('A middle-click finds the web link under the pointer');
await until(async () => await wc.executeJavaScript("getComputedStyle(document.querySelector('.advertisement')).display") === 'none');
assert.equal(await wc.executeJavaScript('typeof window.adExecuted'), 'undefined');
passed.push('network and cosmetic ad blocking remain active');
+4
View File
@@ -262,6 +262,10 @@ If a download fails, the tab shows the cause. Select **Retry** to start the down
Until the engine is installed, web links in your documents open in your system browser.
After a RuneStone update that needs a new engine, a browser tab offers **Update the engine**.
In a page, middle-click a link to open it in a new tab. Middle-click other content to scroll, then move the pointer in the direction to scroll.
Right-click an image for **Open image in new tab**, **Save image as…**, **Copy image**, and **Copy image address**.
**Copy image** keeps the original file. A GIF that you paste into a document or a card keeps its animation.
Use **Settings → Browser** to set the homepage and search engine, manage profiles, block ads, and clear cookies, cache, or history.
**Settings → Browser → Browser engine** shows the installed version. **Remove engine** frees the disk space. Your profiles, bookmarks, and history stay.
Each profile keeps its own cookies and bookmarks. Web bookmarks show in the Bookmarks pane.
+4 -4
View File
@@ -1,11 +1,11 @@
{
"version": "0.1.9",
"version": "0.1.11",
"protocol": 1,
"platforms": {
"windows-x86_64": {
"url": "https://git.knottywyvern.com/kwyvern/RuneStone/releases/download/browser-engine-v0.1.9/RuneStone-Browser_0.1.9_win32-x64.zip",
"bytes": 163623491,
"sha256": "040fbc671a061331a031de280879d5a455f6cda679e9e2c75c8bc4a21e101121"
"url": "https://git.knottywyvern.com/kwyvern/RuneStone/releases/download/browser-engine-v0.1.11/RuneStone-Browser_0.1.11_win32-x64.zip",
"bytes": 163623801,
"sha256": "1e0153b134cebe882b36f74e1f3c2a4ed37acb2caca10548034a8b5d88738d26"
}
}
}
+2 -1
View File
@@ -35,6 +35,7 @@ const COMMANDS: &[&str] = &[
"edit",
"contextAction",
"copiedImage",
"linkAt",
"frameAck",
"createProfile",
"renameProfile",
@@ -481,7 +482,7 @@ impl BrowserState {
let _ = app.emit_to(&source, "browser-tab-moved", json!({ "tabId": id }));
return Ok(worker.routing.lock()?.snapshot(result, owner));
}
if ["closeTab", "navigate", "back", "forward", "reload", "stop", "find", "stopFind", "openExternal", "moveToWindow", "resize", "visible", "focus", "input", "insertText", "edit", "contextAction", "copiedImage", "frameAck", "bookmark", "agentSnapshot"].contains(&command) {
if ["closeTab", "navigate", "back", "forward", "reload", "stop", "find", "stopFind", "openExternal", "moveToWindow", "resize", "visible", "focus", "input", "insertText", "edit", "contextAction", "copiedImage", "linkAt", "frameAck", "bookmark", "agentSnapshot"].contains(&command) {
let id = args["tabId"].as_str().ok_or("Invalid browser tab.")?;
match worker.routing.lock()?.owners.get(id) {
Some(window) if window == owner => {},
+21 -6
View File
@@ -44,7 +44,7 @@
let scrollAnchor = $state<{ x: number; y: number } | null>(null);
let scrollFrame = 0, moveFrame = 0, movePending = false;
let pendingMove: Record<string, unknown> | undefined;
let suppressedRelease = -1;
let suppressedRelease = -1, middlePressed = false;
const result = $derived(current?.find?.text === findText ? current.find : null);
const documentKey = $derived(`${tabId}:${current?.url}:${!!current?.loading}`);
$effect(() => {
@@ -117,6 +117,7 @@
{ label: $t('Copy link address'), icon: 'copy', run: action('copyLink') },
{ label: $t('Save link as…'), icon: 'save', run: action('saveLink') }, { separator: true });
if (context.hasImageContents) items.push(
{ label: $t('Open image in new tab'), icon: 'file-plus', disabled: !context.srcURL, run: () => void newTab(current?.profileId || 'user', context.srcURL) },
{ label: $t('Save image as…'), icon: 'save', disabled: !context.srcURL, run: action('saveImage') },
{ label: $t('Copy image'), icon: 'copy', run: () => copyImage(context) },
{ label: $t('Copy image address'), icon: 'copy', disabled: !context.srcURL, run: action('copyImageAddress') }, { separator: true });
@@ -212,23 +213,37 @@
if (mounted && pendingMove) moveFrame = requestAnimationFrame(flushMove);
});
}
// The frame has the CSS size of the page viewport. A surface point less the frame offset is the same page point.
function pagePoint(point: { x: number; y: number }) {
return { x: Math.max(0, Math.min(width - 1, Math.round(point.x - imageBox.x))), y: Math.max(0, Math.min(height - 1, Math.round(point.y - imageBox.y))) };
}
// A middle-click starts scrolling at once. On a link, it stops the scroll and opens the link in a new tab.
async function openLinkAt(input: { x: number; y: number }) {
const owner = tabId;
const found = await request<{ url: string | null }>('linkAt', { tabId: owner, ...input }).catch(() => null);
if (!found?.url || owner !== tabId || !autoScroll.anchor) return;
stopScroll();
if (middlePressed) suppressedRelease = 1;
void newTab(current?.profileId || 'user', found.url);
}
function pointer(event: MouseEvent | WheelEvent, type: string) {
event.preventDefault(); event.stopPropagation(); if (type === 'mouseDown') textInput.focus({ preventScroll: true });
const rect = surface.getBoundingClientRect();
const point = { x: event.clientX - rect.left, y: event.clientY - rect.top };
if (event.button === 1) middlePressed = type === 'mouseDown';
if (type === 'mouseUp' && event.button === suppressedRelease) { suppressedRelease = -1; return; }
if (type === 'mouseDown' && autoScroll.anchor) { suppressedRelease = event.button; stopScroll(); return; }
if (type === 'mouseDown' && event.button === 1 && ready) {
pendingMove = undefined; cancelAnimationFrame(moveFrame); moveFrame = 0;
autoScroll.start(point); scrollAnchor = point; scrollFrame = requestAnimationFrame(scrollStep); return;
autoScroll.start(point); scrollAnchor = point; scrollFrame = requestAnimationFrame(scrollStep);
void openLinkAt(pagePoint(point)); return;
}
if (autoScroll.anchor) {
if (type === 'mouseMove') autoScroll.move(point);
if (type === 'mouseUp' && event.button === 1) { autoScroll.release(); if (!autoScroll.anchor) stopScroll(); }
if (type === 'mouseWheel') stopScroll(); else return;
}
// The frame has the CSS size of the page viewport. A surface point less the frame offset is the same page point.
const input = { type, x: Math.max(0, Math.min(width - 1, Math.round(point.x - imageBox.x))), y: Math.max(0, Math.min(height - 1, Math.round(point.y - imageBox.y))),
const input = { type, ...pagePoint(point),
button: ['left', 'middle', 'right'][event.button] || 'left', clickCount: event.detail, modifiers: modifiers(event),
...('deltaY' in event ? { deltaY: -event.deltaY * (event.deltaMode === 1 ? 40 : event.deltaMode === 2 ? height : 1), deltaX: -event.deltaX * (event.deltaMode === 1 ? 40 : event.deltaMode === 2 ? width : 1) } : {}) };
if (type === 'mouseWheel') { wheels.push(input as Parameters<WheelQueue['push']>[0]); return; }
@@ -304,7 +319,7 @@
oninput={() => { if (!composing && textInput.value) { void orderedInput('insertText', { text: textInput.value }); textInput.value = ''; } }}
onblur={stopScroll}></textarea>
{#if image && ready && !blank}<img src={image} class:exact={imageBox.exact} style:width={`${imageBox.width}px`} style:height={`${imageBox.height}px`} style:transform={`translate(${imageBox.x}px, ${imageBox.y}px)`} alt={$t("Web page rendered by the browser")} draggable="false" onload={acknowledgeFrame} onerror={acknowledgeFrame}>{/if}
{#if scrollAnchor}<span class="scroll-anchor" style:left={`${scrollAnchor.x}px`} style:top={`${scrollAnchor.y}px`} aria-hidden="true">↕</span>{/if}
{#if scrollAnchor}<span class="scroll-anchor" style:left={`${scrollAnchor.x}px`} style:top={`${scrollAnchor.y}px`} aria-hidden="true"><Icon icon="scroll" /></span>{/if}
</div>
</div>
<style>
@@ -316,7 +331,7 @@
input{flex:1}.profile-choice{max-width:160px;display:flex;align-items:center;gap:var(--rs-menu-icon-gap);cursor:pointer}input:focus-visible,.profile-choice:focus-visible{outline:2px solid var(--rs-focus)}
.surface{position:relative;flex:1;min-height:0;overflow:hidden;outline:none;background:var(--rs-bg)}.surface:focus-visible{box-shadow:inset 0 0 0 1px var(--rs-accent)}
.browser.blank,.blank .surface{background:transparent}
.surface.autoscroll{cursor:all-scroll}.scroll-anchor{position:absolute;transform:translate(-50%,-50%);display:grid;place-items:center;width:24px;height:24px;border:1px solid var(--rs-text);border-radius:50%;background:var(--rs-bg-elevated);color:var(--rs-text);font-size:20px;pointer-events:none;box-shadow:0 1px 4px #0006}
.surface.autoscroll{cursor:all-scroll}.scroll-anchor{position:absolute;transform:translate(-50%,-50%);display:grid;place-items:center;width:26px;height:26px;border:1px solid var(--rs-text);border-radius:50%;background:var(--rs-bg-elevated);color:var(--rs-text);pointer-events:none;box-shadow:0 1px 4px #0006}.scroll-anchor :global(svg){width:20px;height:20px;flex-basis:20px}
img{display:block;pointer-events:none;user-select:none;will-change:transform}img.exact{image-rendering:pixelated}.error{margin:0;padding:5px 10px;color:var(--rs-error);font-size:12px}
.error p{margin:4px 0}.status,.diagnostics{margin:0;padding:8px 10px;font-size:12px;color:var(--rs-text-dim)}
.reconnect{padding:6px 12px;margin:4px 0;border:1px solid var(--rs-border);border-radius:var(--rs-control-radius);background:var(--rs-bg-elevated);color:var(--rs-text);cursor:pointer}
+6
View File
@@ -1679,6 +1679,12 @@ export const messageRows: [string, string, string, string][] = [
"新しいタブでリンクを開く",
"在新标签页中打开链接"
],
[
"Open image in new tab",
"Ouvrir l’image dans un nouvel onglet",
"新しいタブで画像を開く",
"在新标签页中打开图片"
],
[
"Open link in default browser",
"Ouvrir le lien dans le navigateur par défaut",
+2
View File
@@ -34,6 +34,8 @@
<path d="m6 9 6 6 6-6" />
{:else if icon === "chevrons-up-down"}
<path d="m7 15 5 5 5-5M7 9l5-5 5 5" />
{:else if icon === "scroll"}
<path d="M12 3v5m-3-2 3-3 3 3M12 21v-5m-3 2 3 3 3-3M3 12h5m-2-3-3 3 3 3M21 12h-5m2-3 3 3-3 3" /><circle cx="12" cy="12" r="1" />
{:else if icon === "maximize"}
<path d="M8 3H3v5M16 3h5v5M21 16v5h-5M8 21H3v-5" />
{:else if icon === "minimize"}
+1
View File
@@ -23,6 +23,7 @@
| "more"
| "chevron-down"
| "chevrons-up-down"
| "scroll"
| "up"
| "down"
| "maximize"
+26
View File
@@ -139,6 +139,24 @@ await runSmoke('browser/interaction', async ({ browser }) => {
const copied = await page.evaluate(async url => (await import('/src/lib/workspace/copiedImage.ts')).copiedImage(url), gifUrl);
assert.equal(copied, `data:image/gif;base64,${onceGif.toString('base64')}`);
assert.equal(commands.filter(call => call.command === 'copiedImage').length, 1);
// A new browser tab opens in front. Close it, so that the next steps use the first tab again.
async function expectTab(url) {
for (let attempt = 0; attempt < 100 && !(await rpc('state')).tabs.some(tab => tab.url === url); attempt++) await page.waitForTimeout(50);
assert.ok((await rpc('state')).tabs.some(tab => tab.url === url), `A new browser tab opens ${url}`);
await page.keyboard.press('Control+w');
for (let attempt = 0; attempt < 100 && (await rpc('state')).tabs.length > 1; attempt++) await page.waitForTimeout(50);
assert.equal((await rpc('state')).tabs.length, 1);
await page.locator('.browser:not(.blank)[data-browser-state="ready"]').waitFor();
}
await page.mouse.click(initialBox.x + 80, initialBox.y + 340, { button: 'right' });
await page.getByRole('menuitem', { name: 'Open image in new tab', exact: true }).click();
await expectTab(gifUrl);
// A middle-click on a link opens the link in a new tab instead of scrolling.
const linked = `${fixture.url}linked`;
await evaluate(`document.body.innerHTML='<a href="${linked}" style="position:absolute;left:40px;top:300px;display:block;width:200px;height:40px">Linked page</a>';true;`);
await page.mouse.click(initialBox.x + 100, initialBox.y + 320, { button: 'middle' });
await expectTab(linked);
assert.equal(await page.locator('.scroll-anchor').count(), 0, 'A middle-click on a link does not keep scrolling');
await evaluate(`document.body.innerHTML='<canvas width="1000" height="700"></canvas>'; const c=document.querySelector('canvas').getContext('2d'); let n=0; window.testAnimate=true; function draw(){ c.fillStyle='#fff';c.fillRect(0,0,1000,700);c.fillStyle='#5482ff';c.fillRect(n++*5%900,200,80,80);if(window.testAnimate)requestAnimationFrame(draw); } draw();true;`);
await page.locator('.surface img').waitFor();
await page.evaluate(() => { window.decodedFrames = 0; document.querySelector('.surface img').addEventListener('load', () => window.decodedFrames++); });
@@ -162,6 +180,14 @@ await runSmoke('browser/interaction', async ({ browser }) => {
const box = await surface.boundingBox();
const x = box.x + 220, y = box.y + 180;
await page.mouse.click(x, y, { button: 'middle' });
// The marker draws the four-way scroll icon, not a text glyph that depends on the font.
const marker = page.locator('.scroll-anchor');
assert.equal(await marker.locator('svg path').count(), 1);
assert.equal(await marker.evaluate(node => node.textContent.trim()), '');
for (const theme of ['light', 'dark']) {
await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).applyAppearance({ theme: 'default', mode }), theme);
await page.screenshot({ path: path.join(output, `scroll-marker-${theme}.png`), clip: { x: x - 30, y: y - 30, width: 60, height: 60 } });
}
await page.mouse.move(x + 90, y + 120);
await page.waitForTimeout(1500);
const scrolled = await evaluate('({x:scrollX,y:scrollY})');