diff --git a/CHANGELOG.md b/CHANGELOG.md index 28176fd..471bf1e 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.14] - 2026-11-29 ### Changed diff --git a/PRIVACY.md b/PRIVACY.md index 0f60cf6..b2bd171 100644 --- a/PRIVACY.md +++ b/PRIVACY.md @@ -84,6 +84,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 da89b45..e0dd7ca 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 f384db1..cf18675 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -593,6 +593,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 7a7ce07..80f926c 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -481,9 +481,10 @@ async function showMainScreen (status) { loadSidestrSettings(), refreshPasskeySetting(), refreshCurrentSiteBar(), - chrome.storage.local.get(['podkey_auto_sign', 'podkey_auto_lock']).then(({ podkey_auto_sign: autoSign = false, podkey_auto_lock: autoLock = false }) => { + chrome.storage.local.get(['podkey_auto_sign', 'podkey_auto_lock', 'podkey_json_viewer']).then(({ podkey_auto_sign: autoSign = false, podkey_auto_lock: autoLock = false, podkey_json_viewer: jsonViewer = false }) => { document.getElementById('autoSignToggle').checked = autoSign; document.getElementById('autoLockToggle').checked = autoLock === true; + document.getElementById('jsonViewerToggle').checked = jsonViewer === true; }) ]); } @@ -720,6 +721,7 @@ function setupEventListeners () { document.getElementById('copyBtn').addEventListener('click', handleCopy); document.getElementById('autoSignToggle').addEventListener('change', handleAutoSignToggle); document.getElementById('autoLockToggle').addEventListener('change', (event) => chrome.storage.local.set({ podkey_auto_lock: event.target.checked })); + document.getElementById('jsonViewerToggle').addEventListener('change', handleJsonViewerToggle); document.getElementById('sidestrToggle').addEventListener('change', handleSidestrToggle); document.getElementById('exportBtn').addEventListener('click', () => showExportScreen()); document.getElementById('settingsExportBtn').addEventListener('click', () => showExportScreen()); @@ -1133,6 +1135,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; @@ -1243,6 +1250,9 @@ chrome.storage.onChanged.addListener((changes, areaName) => { if ('podkey_auto_lock' in changes) { document.getElementById('autoLockToggle').checked = changes.podkey_auto_lock.newValue === true; } + 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..7437d8c --- /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/json json-viewer.js: the viewer as one sealed 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/json', + commit: '4b7162a52b314cf4502db1129ecb81b88068cacf', + 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 372570b..6f1e5ec 100644 --- a/src/background.js +++ b/src/background.js @@ -21,6 +21,7 @@ import { removeTrustedOrigin, getTrustedOrigins, getAutoSign, + getJsonViewer, getDisabledOrigins, setOriginDisabled, hasLegacyPlaintextKey, @@ -110,7 +111,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); } @@ -146,7 +148,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(); // switching auto-lock on starts the timer for a key that is already unlocked; off stops it if (area === 'local' && AUTO_LOCK_KEY in changes) { getKeypair().then((kp) => (kp ? armIdleTimer() : disarmIdleTimer())).catch(() => {}); 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