mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 09:01:39 -05:00
Enable accessing background window from content script with tri.bg
This commit is contained in:
parent
1522b0e2dc
commit
ee540db193
4 changed files with 10 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
*
|
||||
|
|
|
@ -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, [])
|
||||
|
|
Loading…
Add table
Reference in a new issue