Skip to content

emrg: annotate local pages in the editor's browser mode - #3308

Merged
argszero merged 1 commit into
masterfrom
fix/browser-mode-annotation
Dec 3, 2026
Merged

argszero merged 1 commit into
masterfrom
fix/browser-mode-annotation

Conversation

@argszero

@argszero argszero commented Dec 3, 2026

Copy link
Copy Markdown
Owner

The defect

v0.3.88 and v0.3.89 shipped an annotation panel into a view that has no way to be opened. The panel lived in a second WebContentsView created by ensurePreviewView() and reached through emrg:previewHtml / emrg:closePreview / emrg:getPreviewState / emrg:panelResized — and no renderer file called any of them (grep -rn previewHtml emrg/gui/renderer = 0 hits). There was no button, no menu item and no shortcut, so the feature could not be exercised at all.

What was being asked for is the editor's browser mode — the globe toggle in EditorPanel.tsx (editor-toggle-browser), backed by ensureBrowserView(). That is the surface the host uses, and it had no annotation.

The change

The unopenable view is gone. ensurePreviewView, showPreview, previewRect, updatePreviewBounds, the four IPC channels, the window-resize bounds sync and the renderer's exposure of previewHtml / closePreview / panelResized / getPreviewState are deleted. No channel is left behind without a handler, and no handler without a channel.

The panel moves to the page it belongs to. preview-preload.js becomes annotation-preload.js and is mounted on the browser view. Both are WebContentsViews composited above the app's window, which is why the panel cannot be a DOM layer in the renderer and has to be drawn inside the document — that reason is unchanged, its host is not.

A network page carries nothing. Electron cannot swap a preload on navigation, so the same preload is mounted for every address this view loads, and it asks the address before it builds anything: location.protocol !== "file:" returns before a panel or a listener exists. browser-policy.js gains annotationAllowed(url) for the same question on the main-process side.

These two checks are not two carriers of one rule, and the PR does not treat them as such: the preload's answer decides only whether to draw, while what may leave is decided in one place — ipcMain.on("emrg:pageAnnotate") accepts a batch only from that view's own webContents, only while the address main itself recorded passes annotationAllowed, and it computes the file with fileURLToPath from that address. A file name or an address reported by the page is never used.

The batch reaches the composer unchanged. Up emrg:pageAnnotate, down emrg:pageAnnotation, onPageAnnotation in preload.js, and Shell.tsx still hands the composed message to the composer — queueing, the user record and the session all live on that one path.

Guards

test/annotation-wiring.test.js (rewritten from preview-annotation-wiring.test.js) pins six things:

  • the browser view loads annotation-preload.js and build.files names it — a preload is not a require, so no other scan would put it in app.asar (v0.3.88's own defect);
  • the address is asked before main() runs, at the only main(); call site, so a network page builds no panel and installs no listener;
  • the sender check, the annotationAllowed gate and fileURLToPath are all present, and payload.file / payload.path are absent — the page's own claim is not read;
  • the preload hands the page nothing: no contextBridge, no exposeInMainWorld, no window.emrg (comment-stripped before asserting);
  • the renderer subscribes once and leaves through composeMessage + setComposerSend;
  • the deleted feature stays deleted — the five channels, ensurePreviewView and showPreview are absent from main.js, the five names absent from preload.js, and preview-preload.js does not exist.

browser-policy.test.js gains a case for annotationAllowed (file: in, http/https/about: and "no address at all" out).

Measured

  • cd emrg/gui && npm test — 283 pass, 8 skipped, 0 fail
  • cd emrg/gui/renderer && npm run typecheck && npm test — tsc --noEmit clean, 1283 pass
  • uv run --no-sync python -m pytest tests/ -q — 7000 passed, 36 skipped
  • scripts/check-node-test-count.py — OK: Agent.md documents 1283 renderer + 282 GUI tests, and tests/test_doc_counts.py passes
  • node --check main.js preload.js annotation-preload.js browser-policy.js — clean

The annotation panel shipped in v0.3.88/0.3.89 was mounted in a second
WebContentsView that nothing could open: no button, menu or shortcut called
`emrg:previewHtml`, and `grep -rn previewHtml emrg/gui/renderer` answered 0. The
host was asking for browser mode — the globe toggle in the file editor — the
whole time.

So that view is deleted, with its four IPC channels, its bounds sync and its
renderer-side preload exposure. What it carried moves to where it belongs: the
browser view loads `annotation-preload.js` (the same panel, renamed), and the
preload asks the address before it builds anything, so a document that is not a
local `file:` page gets no panel and no listener. The gate on what leaves is in
the main process, unchanged in shape: the sender must be that view's own
webContents, the address it recorded must be a local file, and the file is
computed from that address with `fileURLToPath` — a path a page reports is never
used.

The channel is `emrg:pageAnnotate` up and `emrg:pageAnnotation` down; the
renderer binds `onPageAnnotation` and hands the batch to the composer.

Measured on this tree: `cd emrg/gui && npm test` 283 pass / 8 skipped,
`renderer` 1283 pass with `tsc --noEmit` clean, `pytest tests/` all pass,
`check-node-test-count.py` and `tests/test_doc_counts.py` agree (Agent.md
1283 + 282 labels).
@argszero

argszero commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

The host waived the three-vote gate for this version (2026-12-03T21:10, in session s_261124_1407_a15803f0: 「豁免」 in answer to whether this release waits for three cycles' votes or takes a zero-vote waiver). The waiver covers v0.3.90 only; it does not carry to the next version.

Gates measured on head 73362f5d before merging:

  • test pass (2m46s), test-windows pass (6m18s)
  • check-merge-freshness.py 3308 — STALE only because CI was still running when it was read; both legs have since concluded green
  • check-merge-landing-diff.py 3308 — 14 paths, every one landed, no path reads backwards
  • check-merge-order.py — 1 open PR, 0 pairs conflict
  • check-merge-tree-health.py — HEALTHY
  • check-merge-plan-suite.py — final tree c190be86, suite OK: 7001 passed, 37 skipped

@argszero
argszero merged commit 20e78df into master Dec 3, 2026
2 checks passed
@argszero
argszero deleted the fix/browser-mode-annotation branch December 3, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant