From 2c13778d4f544b9215e06be7282fdc86226e42d1 Mon Sep 17 00:00:00 2001 From: Melvin Carvalho Date: Sun, 29 Nov 2026 13:20:51 +0100 Subject: [PATCH 1/2] View JSON pages: bundle the JSON / JSON-LD viewer, off by default (#48) The viewer is one vendored file from solid-panes/extension, pinned in vendor/json-viewer/PINS.json. Its content script is registered only while the setting is on, in src/content-scripts.js beside the other three, so a switched-off site leaves it out too. No new permission, no web-accessible resource, no storage access from the page side, no network requests. The full SolidOS panes viewer is separate and not part of this. --- CHANGELOG.md | 11 + PRIVACY.md | 9 + README.md | 14 + popup/popup.html | 10 + popup/popup.js | 12 +- scripts/vendor-json-viewer.js | 59 + src/background.js | 6 +- src/content-scripts.js | 42 +- src/json-viewer-start.js | 14 + src/storage.js | 23 + test/content-scripts.test.js | 78 + test/json-viewer.test.js | 119 + vendor/json-viewer/PINS.json | 13 + vendor/json-viewer/json-viewer.js | 3533 +++++++++++++++++++++++++++++ 14 files changed, 3931 insertions(+), 12 deletions(-) create mode 100644 scripts/vendor-json-viewer.js create mode 100644 src/json-viewer-start.js create mode 100644 test/json-viewer.test.js create mode 100644 vendor/json-viewer/PINS.json create mode 100644 vendor/json-viewer/json-viewer.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e25dfa..336dab3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- **View JSON pages (off by default).** A setting in the popup shows JSON and + JSON-LD pages as a readable tree, with a table view, search, type badges and + followable `@id` links, and a Viewer / Raw switch. It is the viewer from + [solid-panes](https://solid-panes.github.io/json/), vendored as one pinned + file (`vendor/json-viewer/`, checked against `PINS.json` by the tests). With + the setting off its script is not registered, so its code runs on no page. + It needs no new permission, reads no storage, makes no network request, and + is left out of a site Podkey is switched off for. (#48) + ## [0.0.13] - 2026-11-28 ### Added diff --git a/PRIVACY.md b/PRIVACY.md index d852d84..e7119d8 100644 --- a/PRIVACY.md +++ b/PRIVACY.md @@ -83,6 +83,15 @@ Podkey's. Podkey runs the verification code it ships with; nothing is downloaded and executed. Relays and mirrors are third parties with their own policies, and Podkey cannot see or control what they keep. +## Viewing JSON pages (opt-in) + +"View JSON pages" is **off by default**. When you switch it on in the popup's +settings, a page that is a JSON or JSON-LD response is drawn as a readable tree +by a viewer bundled with Podkey. The viewer works on the text your browser has +already loaded, on your device. It makes no network request, sends nothing +anywhere, stores nothing, and has no access to your key. The only thing kept is +the setting itself (on or off), in local storage. + ## Permissions, and why they are needed - **`storage`**: to keep the encrypted key, your public key, your trusted and diff --git a/README.md b/README.md index f542e31..3adcfd6 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,20 @@ Podkey keeps each chain's validated state, so the next spend checks only the blocks since; the settings list the chains in use, and **Forget** drops a chain's signer and its saved state. Turning spends off forgets every chain. +## View JSON pages (optional) + +Off by default. Switch on **View JSON pages** in the popup's settings and a page +that is a JSON, JSON-LD or JSON Lines response is shown as a collapsible tree +with a table view, search, type badges and followable `@id` links. A Viewer / +Raw switch in the corner goes back to the page as the browser showed it. + +The viewer is one vendored file (`vendor/json-viewer/json-viewer.js`, pinned in +`PINS.json`; update with `node scripts/vendor-json-viewer.js`). It is registered +as a content script only while the setting is on, acts only on JSON pages, and +makes no network requests: it reads the text the browser already has. It is +separate from Podkey's signing: it never talks to the key, the worker or the +bridge. + ## Architecture ``` diff --git a/popup/popup.html b/popup/popup.html index e012635..482cd26 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -583,6 +583,16 @@

Podkey

+
+
+
View JSON pages
+
Show JSON and JSON-LD pages as a readable tree. Off by default.
+
+ +
Passkey unlock
diff --git a/popup/popup.js b/popup/popup.js index 445deac..bc63106 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -481,8 +481,9 @@ async function showMainScreen (status) { loadSidestrSettings(), refreshPasskeySetting(), refreshCurrentSiteBar(), - chrome.storage.local.get(['podkey_auto_sign']).then(({ podkey_auto_sign: autoSign = false }) => { + chrome.storage.local.get(['podkey_auto_sign', 'podkey_json_viewer']).then(({ podkey_auto_sign: autoSign = false, podkey_json_viewer: jsonViewer = false }) => { document.getElementById('autoSignToggle').checked = autoSign; + document.getElementById('jsonViewerToggle').checked = jsonViewer === true; }) ]); } @@ -718,6 +719,7 @@ function setupEventListeners () { // Main screen actions document.getElementById('copyBtn').addEventListener('click', handleCopy); document.getElementById('autoSignToggle').addEventListener('change', handleAutoSignToggle); + document.getElementById('jsonViewerToggle').addEventListener('change', handleJsonViewerToggle); document.getElementById('sidestrToggle').addEventListener('change', handleSidestrToggle); document.getElementById('exportBtn').addEventListener('click', () => showExportScreen()); document.getElementById('settingsExportBtn').addEventListener('click', () => showExportScreen()); @@ -1131,6 +1133,11 @@ async function handleAutoSignToggle (event) { await chrome.storage.local.set({ podkey_auto_sign: event.target.checked }); } +// The worker sees the change and registers or removes the viewer's script (#48). +async function handleJsonViewerToggle (event) { + await chrome.storage.local.set({ podkey_json_viewer: event.target.checked === true }); +} + async function loadSidestrSettings () { const s = await sidestrSettings.load(chrome.storage.local); document.getElementById('sidestrToggle').checked = s.enabled; @@ -1238,6 +1245,9 @@ chrome.storage.onChanged.addListener((changes, areaName) => { if ('podkey_auto_sign' in changes) { document.getElementById('autoSignToggle').checked = Boolean(changes.podkey_auto_sign.newValue); } + if ('podkey_json_viewer' in changes) { + document.getElementById('jsonViewerToggle').checked = changes.podkey_json_viewer.newValue === true; + } if ('podkey_sidestr' in changes) { loadSidestrSettings(); } diff --git a/scripts/vendor-json-viewer.js b/scripts/vendor-json-viewer.js new file mode 100644 index 0000000..2d2d1db --- /dev/null +++ b/scripts/vendor-json-viewer.js @@ -0,0 +1,59 @@ +#!/usr/bin/env node +/** + * Vendor the JSON / JSON-LD viewer into vendor/json-viewer/ from a pinned + * upstream commit (#48). + * + * A Manifest V3 extension may not run code it fetches from the network, so + * Podkey carries a pinned copy of the one file it needs: + * + * solid-panes/extension json-viewer.js: the viewer as one file, generated + * there by tools/kernel.mjs. No patches are applied. + * + * PINS.json records the commit and a SHA-256 for the file; + * test/json-viewer-vendor.test.js checks the tree against it. + * Run: `node scripts/vendor-json-viewer.js` (needs git and network), or with + * `--from ` to read an already-reviewed clone instead of fetching. + */ +import { execFileSync } from 'node:child_process'; +import { createHash } from 'node:crypto'; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const PIN = { + name: 'json-viewer', + repo: 'https://github.com/solid-panes/extension', + commit: '11a2accd27c11a2e1fced99b19afcaf484bee7a2', + files: ['json-viewer.js'] +}; + +const rootDir = join(dirname(fileURLToPath(import.meta.url)), '..'); +const outDir = join(rootDir, 'vendor', 'json-viewer'); +const fromAt = process.argv.indexOf('--from'); +let clone = fromAt > -1 ? process.argv[fromAt + 1] : null; +let temp = null; + +if (!clone) { + temp = mkdtempSync(join(tmpdir(), 'podkey-json-viewer-')); + execFileSync('git', ['clone', '--quiet', PIN.repo, temp], { stdio: 'inherit' }); + clone = temp; +} + +try { + mkdirSync(outDir, { recursive: true }); + const files = {}; + for (const file of PIN.files) { + const body = execFileSync('git', ['-C', clone, 'show', `${PIN.commit}:${file}`], { maxBuffer: 64 * 1024 * 1024 }); + writeFileSync(join(outDir, file), body); + files[file] = createHash('sha256').update(body).digest('hex'); + } + const pins = { + note: 'Generated by scripts/vendor-json-viewer.js. Do not edit by hand.', + pins: [{ name: PIN.name, repo: PIN.repo, commit: PIN.commit, files }] + }; + writeFileSync(join(outDir, 'PINS.json'), JSON.stringify(pins, null, 2) + '\n'); + console.log(`vendor/json-viewer: ${Object.keys(files).length} file(s) at ${PIN.commit.slice(0, 7)}`); +} finally { + if (temp) rmSync(temp, { recursive: true, force: true }); +} diff --git a/src/background.js b/src/background.js index 9619062..95d09fa 100644 --- a/src/background.js +++ b/src/background.js @@ -21,6 +21,7 @@ import { removeTrustedOrigin, getTrustedOrigins, getAutoSign, + getJsonViewer, getDisabledOrigins, setOriginDisabled, hasLegacyPlaintextKey, @@ -97,7 +98,8 @@ async function useKeypair () { // Register the content scripts again with the sites that are switched off excluded. async function syncScripts () { try { - await syncContentScripts(Object.keys(await getDisabledOrigins())); + const [disabled, jsonViewer] = await Promise.all([getDisabledOrigins(), getJsonViewer()]); + await syncContentScripts(Object.keys(disabled), { jsonViewer }); } catch (e) { console.error('[Podkey] Could not update content scripts:', e); } @@ -133,7 +135,7 @@ chrome.storage?.onChanged?.addListener((changes, area) => { disarmIdleTimer(); denyAllPending(); } - if (area === 'local' && 'podkey_disabled_origins' in changes) syncScripts(); + if (area === 'local' && ('podkey_disabled_origins' in changes || 'podkey_json_viewer' in changes)) syncScripts(); if ((area === 'session' && 'podkey_private_key' in changes) || (area === 'local' && ['podkey_trusted_origins', 'podkey_auto_sign', 'podkey_disabled_origins', 'podkey_sidestr', 'podkey_sidestr_signers'] .some((k) => k in changes))) { diff --git a/src/content-scripts.js b/src/content-scripts.js index 3cdfce1..7043220 100644 --- a/src/content-scripts.js +++ b/src/content-scripts.js @@ -11,6 +11,13 @@ * * The two page-world scripts replace the old