mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-01 12:02:05 +00:00
Per-kind renderers, each a lazy split chunk: plain-iframe video/maps (wheel chains to the transcript; maps gate scroll behind ⌘), the in-document blockquote-script path for X/Instagram, the dark Spotify player, and the YouTube iframe. Adds Mermaid and DOMPurify-sanitised SVG fences and GFM alert callouts, all sized to 33dvh and theme-matched to avoid white color-scheme artifacts. Main-process stamps a Referer on YouTube embed requests.
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
'use strict'
|
|
|
|
const { session } = require('electron')
|
|
|
|
const EMBED_SESSION_PARTITION = 'persist:hermes-embed'
|
|
const EMBED_REFERER = 'https://www.youtube.com/'
|
|
const YOUTUBE_REFERER_HOST_RE =
|
|
/(^|\.)(youtube\.com|youtube-nocookie\.com|googlevideo\.com|ytimg\.com|youtubei\.googleapis\.com)$/i
|
|
|
|
function installEmbedRefererForSession(embedSession) {
|
|
if (!embedSession) {
|
|
return
|
|
}
|
|
|
|
embedSession.webRequest.onBeforeSendHeaders((details, callback) => {
|
|
let host = ''
|
|
|
|
try {
|
|
host = new URL(details.url).hostname
|
|
} catch {
|
|
host = ''
|
|
}
|
|
|
|
if (!YOUTUBE_REFERER_HOST_RE.test(host)) {
|
|
callback({ requestHeaders: details.requestHeaders })
|
|
return
|
|
}
|
|
|
|
const headers = { ...details.requestHeaders }
|
|
|
|
if (!headers.Referer && !headers.referer) {
|
|
headers.Referer = EMBED_REFERER
|
|
}
|
|
|
|
callback({ requestHeaders: headers })
|
|
})
|
|
}
|
|
|
|
/** Stamp Referer on YouTube requests in the embed webview partition only. */
|
|
function installEmbedReferer() {
|
|
try {
|
|
installEmbedRefererForSession(session.fromPartition(EMBED_SESSION_PARTITION))
|
|
} catch {
|
|
// Non-fatal: embeds still render; YouTube may show referer errors.
|
|
}
|
|
}
|
|
|
|
module.exports = { installEmbedReferer }
|