Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions PRIVACY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
10 changes: 10 additions & 0 deletions popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,16 @@ <h1>Podkey</h1>
<span class="slider"></span>
</label>
</div>
<div class="settings-item settings-separated">
<div class="settings-text">
<div class="settings-label" id="jsonViewerLabel">View JSON pages</div>
<div class="settings-desc">Show JSON and JSON-LD pages as a readable tree. Off by default.</div>
</div>
<label class="toggle">
<input type="checkbox" id="jsonViewerToggle" aria-labelledby="jsonViewerLabel" />
<span class="slider"></span>
</label>
</div>
<div class="settings-item settings-separated">
<div class="settings-text">
<div class="settings-label">Passkey unlock</div>
Expand Down
12 changes: 11 additions & 1 deletion popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
]);
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
59 changes: 59 additions & 0 deletions scripts/vendor-json-viewer.js
Original file line number Diff line number Diff line change
@@ -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 <local clone>` 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 });
}
6 changes: 4 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
removeTrustedOrigin,
getTrustedOrigins,
getAutoSign,
getJsonViewer,
getDisabledOrigins,
setOriginDisabled,
hasLegacyPlaintextKey,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(() => {});
Expand Down
42 changes: 33 additions & 9 deletions src/content-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
*
* The two page-world scripts replace the old <script src> injection and the
* web_accessible_resources it needed, which let any site probe for Podkey.
*
* One more script is registered only while its setting is on (#48):
*
* podkey-json-viewer isolated world: shows a JSON or JSON-LD page readably
*
* It is the vendored viewer (vendor/json-viewer/) and one line that starts it.
* With the setting off it is not registered, so its code is on no page.
*/

const SCRIPTS = [
Expand All @@ -19,6 +26,15 @@ const SCRIPTS = [
{ id: 'podkey-provider', js: ['src/nostr-provider.js'], world: 'MAIN' }
];

// Registered only while switched on; unregistered when switched off.
const OPTIONAL_SCRIPTS = {
jsonViewer: {
id: 'podkey-json-viewer',
js: ['vendor/json-viewer/json-viewer.js', 'src/json-viewer-start.js'],
world: 'ISOLATED'
}
};

/**
* Match patterns for the origins to leave out. A single invalid pattern makes
* Chrome reject the whole call, which would leave Podkey on no site at all, so
Expand All @@ -43,45 +59,53 @@ function excludeMatchesFor (disabledOrigins) {
// them so a get-then-register never races into "Duplicate script ID".
let queue = Promise.resolve();

async function sync (disabledOrigins) {
async function sync (disabledOrigins, options) {
const scripting = globalThis.chrome?.scripting;
if (!scripting?.registerContentScripts) return;
try {
await register(scripting, excludeMatchesFor(disabledOrigins));
await register(scripting, excludeMatchesFor(disabledOrigins), options);
} catch (error) {
// Chrome rejects the whole call over one pattern it dislikes, which would
// leave Podkey on no site at all. Being on everywhere is the lesser fault:
// the worker still refuses every request from a switched-off site.
console.error('[Podkey] Could not leave out switched-off sites:', error);
await register(scripting, []);
await register(scripting, [], options);
}
}

async function register (scripting, excludeMatches) {
const wanted = SCRIPTS.map((script) => ({
async function register (scripting, excludeMatches, options) {
const optional = Object.entries(OPTIONAL_SCRIPTS);
const scripts = [...SCRIPTS, ...optional.filter(([name]) => options?.[name] === true).map(([, script]) => script)];
const wanted = scripts.map((script) => ({
...script,
matches: ['<all_urls>'],
excludeMatches,
runAt: 'document_start',
allFrames: false,
persistAcrossSessions: true
}));
const existing = await scripting.getRegisteredContentScripts({ ids: SCRIPTS.map((s) => s.id) });
const known = [...SCRIPTS.map((s) => s.id), ...optional.map(([, s]) => s.id)];
const existing = await scripting.getRegisteredContentScripts({ ids: known });
const have = new Set(existing.map((s) => s.id));
const want = new Set(wanted.map((s) => s.id));
const toUpdate = wanted.filter((s) => have.has(s.id));
const toRegister = wanted.filter((s) => !have.has(s.id));
const toRemove = [...have].filter((id) => !want.has(id));
if (toRemove.length) await scripting.unregisterContentScripts({ ids: toRemove });
if (toUpdate.length) await scripting.updateContentScripts(toUpdate);
if (toRegister.length) await scripting.registerContentScripts(toRegister);
}

/**
* Registers or updates the three scripts, leaving out `disabledOrigins`.
* Registers or updates the three scripts, leaving out `disabledOrigins`, and
* registers or removes the optional ones to match `options`.
* Idempotent. Does nothing where chrome.scripting is absent (tests).
* @param {string[]} disabledOrigins origins such as "https://example.com"
* @param {{ jsonViewer?: boolean }} [options] optional scripts to switch on
* @returns {Promise<void>}
*/
export function syncContentScripts (disabledOrigins) {
const run = queue.then(() => sync(disabledOrigins));
export function syncContentScripts (disabledOrigins, options = {}) {
const run = queue.then(() => sync(disabledOrigins, options));
queue = run.catch(() => {});
return run;
}
14 changes: 14 additions & 0 deletions src/json-viewer-start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Podkey - starts the bundled JSON / JSON-LD viewer (#48).
*
* Registered by src/content-scripts.js, after vendor/json-viewer/json-viewer.js,
* and only while "View JSON pages" is switched on in the popup; a site Podkey is
* switched off for is left out like the other scripts. So being loaded at all
* means the setting is on.
*
* The viewer acts only when the page is a JSON or JSON Lines response shown as
* text. It reads no storage, sends no messages and makes no requests, and this
* script touches neither chrome.runtime nor the bridge (src/injected.js), which
* runs in the same isolated world.
*/
globalThis.SolidJsonViewer?.start({ enabled: true });
23 changes: 23 additions & 0 deletions src/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const STORAGE_KEYS = {
TRUSTED_ORIGINS: 'podkey_trusted_origins',
AUTO_SIGN: 'podkey_auto_sign',
DISABLED_ORIGINS: 'podkey_disabled_origins',
JSON_VIEWER: 'podkey_json_viewer',
PROFILES: 'podkey_profiles',
CURRENT_PROFILE: 'podkey_current_profile'
};
Expand Down Expand Up @@ -199,6 +200,28 @@ export async function setAutoSign(enabled) {
});
}

/**
* Whether JSON and JSON-LD pages are shown with the bundled viewer (#48).
* Off unless the person switches it on in the popup.
* @returns {Promise<boolean>}
*/
export async function getJsonViewer() {
const { [STORAGE_KEYS.JSON_VIEWER]: on = false } =
await chrome.storage.local.get([STORAGE_KEYS.JSON_VIEWER]);

return on === true;
}

/**
* Switch the JSON viewer on or off.
* @param {boolean} enabled
*/
export async function setJsonViewer(enabled) {
await chrome.storage.local.set({
[STORAGE_KEYS.JSON_VIEWER]: enabled === true
});
}

/**
* The sites the person has switched Podkey off for.
* @returns {Promise<Object>} Map of origin -> { addedAt }
Expand Down
Loading
Loading