fix(chrome-ext): unbreak Proton Pass autofill — install browser.permissions on SW + lock chrome
Autofill (form-field icons, dropdown UI) never appeared in webview guests
because the Proton Pass background service worker aborted at sync init.
Root cause: Electron's native `browser` polyfill in service-worker contexts
exposes only the APIs Electron implements natively (action, alarms,
extension, i18n, management, offscreen, runtime, scripting, storage, tabs,
webRequest) — `permissions` is not in that list. Proton's BG calls
`browser.permissions.onAdded.addListener(...)` synchronously during init,
throws TypeError, and aborts. With BG aborted, no chrome.runtime.onMessage
handler is registered, so the orchestrator content script's
LOAD_CONTENT_SCRIPT message goes unanswered, client.js never gets injected,
and the autofill UI never appears.
Compounding: Proton's bundled "extension API isolation" feature schedules a
`setTimeout(0)` that replaces `globalThis.chrome` with a Proxy that returns
errors for every property except 'app'. In page contexts, content scripts
disable this via the orchestrator's call to `uE()`. In SW contexts, nothing
calls `uE()`, so the wrap fires and would clobber chrome.* access for the
rest of the SW lifetime — *if* anything reached the addListener line.
Fix in scripts/patch-chrome-extensions.js's PERMISSIONS_SHIM:
- Install `globalThis.browser.permissions = _shimPerms` (locked
non-writable / non-configurable) immediately after the chrome wrap. This
satisfies Proton's webextension-polyfill consumer and unblocks BG init.
- Lock `globalThis.chrome` itself with writable:false / configurable:false
so Proton's setTimeout-based Proxy-wrap can't clobber the binding. The
follow-on assignment fails with "Cannot assign to read only property" —
benign, since no critical addListener calls remain after that point.
Also adds an opt-in diagnostic shim (PEEK_PROTON_DIAG=1 at patch time)
that wraps chrome.runtime.onMessage and chrome.scripting.executeScript
with loggers writing to chrome.storage.local under '__peekProtonDiag'.
Off by default; useful for future webview-extension debugging.
Adds `tests/desktop/proton-pass-autofill.spec.ts`: opens a local login
form in a Peek page tile, waits up to 10s for any data-protonpass-* /
proton-class / chrome-extension iframe to appear in the webview DOM,
asserts at least one such marker exists.