MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / initialize

Function initialize

src/injected/web/index.js:17–54  ·  view source on GitHub ↗
(invokeHost, console)

Source from the content-addressed store, hash-verified

15const grantlessUsage = createNullObj();
16
17export default function initialize(invokeHost, console) {
18 if (PAGE_MODE_HANDSHAKE) {
19 window::on(PAGE_MODE_HANDSHAKE + '*', e => {
20 e = e::getDetail();
21 bindEvents(e[0], e[1], bridge);
22 }, { __proto__: null, once: true, capture: true });
23 window::fire(new SafeCustomEvent(PAGE_MODE_HANDSHAKE));
24 bridge.mode = PAGE;
25 addHandlers({
26 /** @this {Node} contentWindow */
27 WriteVault(id) {
28 this[id] = VAULT;
29 },
30 });
31 /* Can't use a detached `console` in Chrome 109+ due to https://crrev.com/1063194 */
32 if (!IS_FIREFOX) {
33 for (const m of CONSOLE_METHODS) {
34 logging[m] = (...args) => bridge.post('Log', [m, args]);
35 }
36 /** @this {GMContext} */
37 GM_API_CTX.GM_log = function (...args) {
38 bridge.post('Log', ['log', safeConcat([`[${this.displayName}]`], args)]);
39 };
40 }
41 } else {
42 bridge.mode = CONTENT;
43 bridge.post = (cmd, data, node) => {
44 invokeHost({ cmd, data, node }, CONTENT);
45 };
46 global.chrome = undefined;
47 global.browser = undefined;
48 logging = console; // eslint-disable-line no-global-assign
49 return (cmd, data, realm, node) => {
50 if (process.env.DEBUG) console.info('[bridge.guest.content] received', { cmd, data, node });
51 bridge.onHandle({ cmd, data, node });
52 };
53 }
54}
55
56addHandlers({
57 Command({ id, key, evt }) {

Callers

nothing calls this directly

Calls 5

bindEventsFunction · 0.90
addHandlersFunction · 0.90
safeConcatFunction · 0.90
onFunction · 0.85
fireFunction · 0.50

Tested by

no test coverage detected