diff --git a/src/background.ts b/src/background.ts index 2f55c40a..54d2ec5c 100644 --- a/src/background.ts +++ b/src/background.ts @@ -4,6 +4,7 @@ import * as proxy_background from "@src/lib/browser_proxy_background" import * as controller from "@src/lib/controller" +import { omniscient_controller } from "@src/lib/omniscient_controller" import * as perf from "@src/perf" import { listenForCounters } from "@src/perf" import * as messaging from "@src/lib/messaging" @@ -259,6 +260,7 @@ const messages = { downloadUrlAs: download_background.downloadUrlAs, }, browser_proxy_background: { shim: proxy_background.shim }, + omniscient_background: omniscient_controller, } export type Messages = typeof messages diff --git a/src/content.ts b/src/content.ts index a3a6385a..4e740b42 100644 --- a/src/content.ts +++ b/src/content.ts @@ -96,6 +96,7 @@ const excmds = await import("@src/.excmds_content.generated") const finding_content = await import("@src/content/finding") const itertools = await import("@src/lib/itertools") const messaging = await import("@src/lib/messaging") +const backgroundProxy = await import("@src/lib/tabs") const State = await import("@src/state") const webext = await import("@src/lib/webext") const perf = await import("@src/perf") @@ -208,6 +209,7 @@ config.getAsync("preventautofocusjackhammer").then(allowautofocus => { }) ;(window as any).tri = Object.assign(Object.create(null), { browserBg: webext.browserBg, + bg: backgroundProxy.backgroundProxy, commandline_content, convert, config, diff --git a/src/excmds.ts b/src/excmds.ts index a76ae610..22265f51 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -5853,6 +5853,7 @@ async function js_helper(str: string[]) { * - -r load the js source from a Javascript file relative to your RC file. (NB: will throw an error if no RC file exists) * * Some of Tridactyl's functions are accessible here via the `tri` object. Just do `console.log(tri)` in the web console on the new tab page to see what's available. + * `tri.bg` is an object enabling access to the background script's context. It works similarly to the `tri.tabs` objects documented in the [[jsb]] documentation. * * If you want to pipe an argument to `js`, you need to use the "-p" flag or "-d" flag with an argument and then use the JS_ARG global variable, e.g: * diff --git a/src/lib/tabs.ts b/src/lib/tabs.ts index 7339ef4b..3f6d708a 100644 --- a/src/lib/tabs.ts +++ b/src/lib/tabs.ts @@ -1,10 +1,13 @@ import * as Messaging from "@src/lib/messaging" const allTabs = -1 +const background = -2 const msg = (tabId, ...args) => { if (tabId === allTabs) { return Messaging.messageAllTabs("omniscient_content", ...args) + } else if (tabId === background) { + return (Messaging.message as any)("omniscient_background", args[0], args[1][0]) } else { return Messaging.messageTab(tabId, "omniscient_content", ...args) } @@ -85,3 +88,5 @@ export const tabsProxy = new Proxy(Object.create(null), { throw new Error(`'tabs' object can only be accessed by a number (e.g. tabs[3]) or a string (e.g. tabs.document or tabs['document']). Type of accessor: "${typeof p}"`) }, }) + +export const backgroundProxy = tabProxy(background, [])