Update summon browser
Release rolling / release (push) Failing after 5m54s

This commit is contained in:
Raven Scott
2026-08-13 00:42:27 -04:00
parent 8bb8254c42
commit dfb5638c95
26 changed files with 3027 additions and 164 deletions
@@ -44,7 +44,7 @@ function bareSummonCreateSession(ctx, opts) {
tabs: [bareSummonCreateTab(opts.url || 'about:summon')],
current: 0,
bookmarks: Array.isArray(opts.bookmarks) ? opts.bookmarks.slice() : [],
config: opts.config || { javascript: false, images: 'alt', numbers: true },
config: opts.config || { javascript: true, images: 'alt', numbers: true },
cols: opts.cols || 80
}
}
@@ -104,34 +104,89 @@ function bareSummonAboutBody(kind, session) {
return '<html><body><h1>Net</h1><p>HTTP via ctx.httpFetch. Allow/deny: BARE_OS_HTTP_ALLOWLIST / DENYLIST.</p></body></html>'
}
return (
'<html><body><h1>summon</h1><p>Text browser for Bare OS. JS is off. Default engine is first-party HTML/CSS.</p>' +
'<p>Type a URL (g) or open a bookmark. Try <a href="about:bookmarks">about:bookmarks</a>.</p></body></html>'
'<html><body><h1>summon</h1><p>Text browser for Bare OS. Page JS runs in a Bare VM (ctx.bare.bareVm) when present.</p>' +
'<p>Type a URL (g) or open a bookmark. Try <a href="about:bookmarks">about:bookmarks</a>. Toggle JS with J.</p></body></html>'
)
}
function bareSummonApplyDocument(session, tab, html, url) {
var doc = bareSummonParseHtml(html, {})
function bareSummonCollectInlineSheets(doc) {
var inline = []
function collectStyle(n) {
if (n && n.type === 'element' && n.name === 'style') {
inline.push(bareSummonParseStylesheet(bareSummonTextContent(n)))
}
var ch = (n && n.children) || []
for (var i = 0; i < ch.length; i++) collectStyle(ch[i])
var i
for (i = 0; i < ch.length; i++) collectStyle(ch[i])
}
collectStyle(doc.head)
tab.sheets = inline
var layout = bareSummonLayout(doc, {
if (doc) {
collectStyle(doc.head)
collectStyle(doc.body)
}
return inline
}
function bareSummonFinishLayout(session, tab, url) {
var sheets = (tab.inlineSheets || []).concat(tab.fetchedSheets || [])
tab.sheets = sheets
var layout = bareSummonLayout(tab.doc, {
cols: session.cols,
sheets: inline,
sheets: sheets,
numbers: session.config.numbers !== false
})
tab.doc = doc
tab.layout = layout
tab.title = layout.title || (tab.doc && tab.doc.title) || url || tab.url
return tab
}
function bareSummonApplyDocument(session, tab, html, url) {
var doc = bareSummonParseHtml(html, {})
tab.doc = doc
tab.source = html
tab.title = layout.title || doc.title || url
tab.scriptsBlocked = doc.scriptsBlocked || 0
tab.url = url
tab.inlineSheets = bareSummonCollectInlineSheets(doc)
tab.fetchedSheets = tab.fetchedSheets || []
tab.scriptsBlocked = doc.scriptsBlocked || 0
tab.js = tab.js || { ran: 0, engine: 'off', errors: [], logs: [] }
bareSummonFinishLayout(session, tab, url)
}
async function bareSummonEnhanceDocument(session, tab, url) {
if (!tab || !tab.doc) return tab
var hrefs = tab.doc.stylesheets || []
var fetched = []
var i
for (i = 0; i < hrefs.length && i < 4; i++) {
var abs = bareSummonResolveUrl(hrefs[i], url)
if (!abs || !bareSummonIsHttp(abs)) continue
try {
var res = await bareSummonFetch(session.ctx, abs.href, {
jar: session.jar
})
if (res && res.body) fetched.push(bareSummonParseStylesheet(res.body))
else tab.stylesBlocked = (tab.stylesBlocked || 0) + 1
} catch (e) {
tab.stylesBlocked = (tab.stylesBlocked || 0) + 1
}
}
tab.fetchedSheets = fetched
if (session.config && session.config.javascript !== false) {
tab.js = await bareSummonRunDocumentJs(session, tab.doc, url)
tab.inlineSheets = bareSummonCollectInlineSheets(tab.doc)
tab.scriptsBlocked = tab.js.blocked
tab.title = (tab.doc && tab.doc.title) || tab.title
} else {
tab.js = {
ran: 0,
engine: 'off',
blocked:
(tab.doc.scripts && tab.doc.scripts.length) || tab.scriptsBlocked || 0,
errors: [],
logs: []
}
}
bareSummonFinishLayout(session, tab, url)
return tab
}
function bareSummonRelayout(session) {
@@ -170,6 +225,7 @@ async function bareSummonNavigate(session, urlStr, opts) {
bareSummonAboutBody(kind, session),
resolved.href
)
await bareSummonEnhanceDocument(session, tab, resolved.href)
tab.status = 200
tab.loading = false
return tab
@@ -193,6 +249,7 @@ async function bareSummonNavigate(session, urlStr, opts) {
text || '<html><body>(empty file)</body></html>',
resolved.href
)
await bareSummonEnhanceDocument(session, tab, resolved.href)
tab.status = buf ? 200 : 404
} catch (e) {
tab.error = (e && e.message) || String(e)
@@ -223,6 +280,7 @@ async function bareSummonNavigate(session, urlStr, opts) {
'</pre></body></html>'
}
bareSummonApplyDocument(session, tab, body, fetched.url || resolved.href)
await bareSummonEnhanceDocument(session, tab, fetched.url || resolved.href)
tab.loading = false
return tab
}