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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- **"Open in SolidOS" in the JSON viewer.** A small link beside the Viewer / Raw
switch opens the same address in the SolidOS data browser, where panes can
show it. For a JSON-LD document that is about one thing (its main entity, or
a `#me` or `#this`), the link names that thing rather than the document, so
SolidOS opens the matching pane. It is only a link: nothing is requested
unless you click it. (#50)

### Changed

- Bundled JSON viewer updated to 0.0.2 (`vendor/json-viewer/`, `PINS.json`).

## [0.0.15] - 2026-11-29

### Added
Expand Down
5 changes: 5 additions & 0 deletions PRIVACY.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ 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.

The viewer shows an "Open in SolidOS" link. It is an ordinary link: nothing
happens unless you click it. If you do, a new tab opens the SolidOS data
browser at solidos.org with the address of the page you were viewing, so that
site sees that address, as any site you open a link to would.

## Permissions, and why they are needed

- **`storage`**: to keep the encrypted key, your public key, your trusted and
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,16 @@ chain's signer and its saved state. Turning spends off forgets every chain.
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.
Raw switch in the corner goes back to the page as the browser showed it. Beside
it, **Open in SolidOS** opens the same address in the SolidOS data browser, for
a view with panes; a JSON-LD document about one thing (its main entity, `#me`
or `#this`) is opened on that thing.

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
makes no network requests: it reads the text the browser already has (the
SolidOS link is an ordinary link, followed only if you click it). It is
separate from Podkey's signing: it never talks to the key, the worker or the
bridge.

Expand Down
2 changes: 1 addition & 1 deletion scripts/vendor-json-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { fileURLToPath } from 'node:url';
const PIN = {
name: 'json-viewer',
repo: 'https://github.com/solid-panes/json',
commit: '4b7162a52b314cf4502db1129ecb81b88068cacf',
commit: '44c440eb8e137451a460f34372751dd1a3d80a68',
files: ['json-viewer.js']
};

Expand Down
7 changes: 6 additions & 1 deletion src/json-viewer-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
* switched off for is left out like the other scripts. So being loaded at all
* means the setting is on.
*
* solidosLink adds an "Open in SolidOS" link beside the Viewer / Raw switch: a
* plain link to the SolidOS data browser with this page's address (or the thing
* the document is about: its main entity, #me or #this). Nothing is requested
* unless the person clicks it.
*
* 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 });
globalThis.SolidJsonViewer?.start({ enabled: true, solidosLink: true });
2 changes: 1 addition & 1 deletion test/json-viewer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('src/json-viewer-start.js', () => {
const sandbox = { SolidJsonViewer: { start: (o) => { calls.push(o); return true; } } };
sandbox.globalThis = sandbox;
vm.runInNewContext(src, sandbox);
assert.equal(JSON.stringify(calls), JSON.stringify([{ enabled: true }])); // made in another context, so compared as text
assert.equal(JSON.stringify(calls), JSON.stringify([{ enabled: true, solidosLink: true }])); // made in another context, so compared as text
});

it('does not throw where the viewer is absent', () => {
Expand Down
4 changes: 2 additions & 2 deletions vendor/json-viewer/PINS.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{
"name": "json-viewer",
"repo": "https://github.com/solid-panes/json",
"commit": "4b7162a52b314cf4502db1129ecb81b88068cacf",
"commit": "44c440eb8e137451a460f34372751dd1a3d80a68",
"files": {
"json-viewer.js": "96c264366a36268a8668b183ad14641bcf82fb9015aa947cf84d7e6b2972c0d6"
"json-viewer.js": "aa066aab7b00db3a4b0c14945043e1728379259b692f11070b19b3e25e0f9e1c"
}
}
]
Expand Down
68 changes: 59 additions & 9 deletions vendor/json-viewer/json-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// json-viewer.js — the JSON / JSON-LD viewer as one file. GENERATED by tools/kernel.mjs from
// json-pane.js and host/*.js in https://github.com/solid-panes/json : do not edit here.
// Version 0.0.1.
// Version 0.0.2.
//
// For a browser extension's content script (isolated world), loaded at document_start. It defines
// one name, SolidJsonViewer, and does nothing until the carrier calls
Expand Down Expand Up @@ -3056,7 +3056,54 @@ return pane
return n >= 2
}

H.detect = { page, onlyPre, kindOf }
// What a JSON-LD document is about, as a fragment ('#me') of this document, or null.
// In order: the thing declared as its main one, in either direction (the document says
// schema.org mainEntity or FOAF primaryTopic; or a thing says mainEntityOfPage or
// isPrimaryTopicOf, pointing at this document); else a thing whose @id is #me (the convention
// for a person); else one whose @id is #this (for a thing). Only things inside this document
// count: an @id elsewhere is never followed. Looks at the top level and at @graph.
function topic (text) {
if (!/#me\b|#this\b|mainEntity|rimaryTopic/.test(text)) return null // most JSON: no second parse
try {
const here = location.href.split('#')[0]
const local = v => {
const id = typeof v === 'string' ? v : v && typeof v === 'object' && !Array.isArray(v) ? v['@id'] || v.id : null
if (typeof id !== 'string') return null
const frag = id[0] === '#' ? id : id.startsWith(here + '#') ? id.slice(here.length) : null
return frag && /^#[^\s#]+$/.test(frag) ? frag : null
}
const data = JSON.parse(text)
const nodes = []
for (const top of Array.isArray(data) ? data : [data]) {
if (!top || typeof top !== 'object') continue
nodes.push(top)
if (Array.isArray(top['@graph'])) for (const n of top['@graph']) if (n && typeof n === 'object') nodes.push(n)
}
const MAIN = /^(?:(?:schema:|https?:\/\/schema\.org\/)?mainEntity|(?:foaf:|http:\/\/xmlns\.com\/foaf\/0\.1\/)?primaryTopic)$/
for (const n of nodes) {
for (const k of Object.keys(n)) {
if (!MAIN.test(k)) continue
for (const v of Array.isArray(n[k]) ? n[k] : [n[k]]) { const f = local(v); if (f) return f }
}
}
// the reverse direction: a thing in this document that says this document is its page
const OF = /^(?:(?:schema:|https?:\/\/schema\.org\/)?mainEntityOfPage|(?:foaf:|http:\/\/xmlns\.com\/foaf\/0\.1\/)?isPrimaryTopicOf)$/
const thisDoc = v => {
const id = typeof v === 'string' ? v : v && typeof v === 'object' && !Array.isArray(v) ? ('@id' in v ? v['@id'] : v.id) : null // "" means this document
if (typeof id !== 'string' || id.includes('#')) return false
try { return new URL(id, here).href === here } catch (e) { return false }
}
for (const n of nodes) {
const f = local(n)
if (!f) continue
for (const k of Object.keys(n)) if (OF.test(k) && (Array.isArray(n[k]) ? n[k] : [n[k]]).some(thisDoc)) return f
}
const ids = new Set(nodes.map(n => local(n)).filter(Boolean))
return ids.has('#me') ? '#me' : ids.has('#this') ? '#this' : null
} catch (e) { return null }
}

H.detect = { page, onlyPre, kindOf, topic }
})()

// ---- host/shim.js
Expand Down Expand Up @@ -3317,11 +3364,14 @@ return pane

// "Open in SolidOS": a plain link to the SolidOS data browser with this page's address. Only a
// link: nothing is requested unless it is clicked. Not for file: or other non-web addresses.
function solidosLink () {
function solidosLink (topic) {
// The address handed over: where the reader has navigated to (a #fragment), else the thing the
// document is about (topic, from H.detect.topic), else the document.
const target = () => location.hash ? location.href : location.href + (topic || '')
if (!/^https?:$/.test(location.protocol)) return null
const a = document.createElement('a')
a.className = 'solidos'
a.href = 'https://solidos.org/docs/browser/?uri=' + encodeURIComponent(location.href)
a.href = 'https://solidos.org/docs/browser/?uri=' + encodeURIComponent(target())
a.target = '_blank'
a.rel = 'noopener noreferrer'
a.title = 'Open this address in the SolidOS data browser, which loads panes from your tool index'
Expand All @@ -3335,14 +3385,14 @@ return pane
const span = document.createElement('span')
span.textContent = 'Open in SolidOS'
a.append(span, svg)
addEventListener('hashchange', () => { a.href = 'https://solidos.org/docs/browser/?uri=' + encodeURIComponent(location.href) })
addEventListener('hashchange', () => { a.href = 'https://solidos.org/docs/browser/?uri=' + encodeURIComponent(target()) })
return a
}

// The corner: the SolidOS link and a small Viewer / Raw switch. want: { link, rawSwitch }.
// The corner: the SolidOS link and a small Viewer / Raw switch. want: { link, rawSwitch, topic }.
// onMode('viewer' | 'raw') is called when the switch is used. null when there is nothing to show.
function corner (onMode, want) {
const link = want.link ? solidosLink() : null
const link = want.link ? solidosLink(want.topic) : null
if (!link && !want.rawSwitch) return null
const { host, root } = pillRoot('jsonviewer-toggle')
const dock = document.createElement('div')
Expand Down Expand Up @@ -3394,7 +3444,7 @@ return pane
// belongs to a module above. A host with several panes and tabs has an entry of its own.
(() => {
const H = HOST
H.version = '0.0.1'
H.version = '0.0.2'
const JSON_PANE = {
name: 'json-viewer',
file: 'json-pane.js',
Expand Down Expand Up @@ -3456,7 +3506,7 @@ return pane
fit.el = H.panes.mount(fit)
fit.el.id = 'pane-' + fit.info.name
document.body.insertBefore(fit.el, raw)
const corner = H.controls.corner(mode => { fit.el.hidden = mode === 'raw'; raw.hidden = mode !== 'raw' }, { link: opts.solidosLink, rawSwitch: true })
const corner = H.controls.corner(mode => { fit.el.hidden = mode === 'raw'; raw.hidden = mode !== 'raw' }, { link: opts.solidosLink, rawSwitch: true, topic: opts.solidosLink && kind === 'json' ? H.detect.topic(text) : null })
if (corner) document.body.append(corner)
show()
})().catch(e => { show(); console.warn('JSON viewer:', e) })
Expand Down
Loading