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

Function webAddElement

src/injected/web/gm-api.js:207–225  ·  view source on GitHub ↗
(parent, tag, attrs)

Source from the content-addressed store, hash-verified

205}
206
207function webAddElement(parent, tag, attrs) {
208 let el, err;
209 bridge.call('AddElement', { tag, attrs }, parent, function _(res, cbErr) {
210 el = this;
211 err = cbErr;
212 });
213 // DOM error in content script can't be caught by a page-mode userscript so we rethrow it here
214 if (err) throw err;
215 /* A Promise polyfill is not actually necessary because DOM messaging is synchronous,
216 but we keep it for compatibility with GM_addStyle in VM of 2017-2019
217 https://github.com/violentmonkey/violentmonkey/issues/217
218 as well as for GM_addElement in Tampermonkey. */
219 return setOwnProp(el, 'then', async cb => (
220 // Preventing infinite resolve loop
221 delete el.then
222 // Native Promise ignores non-function
223 && (isFunction(cb) ? cb(el) : el)
224 ));
225}
226
227/**
228 * @param {GMContext} context

Callers 2

GM_addElementFunction · 0.85
GM_addStyleFunction · 0.85

Calls 3

setOwnPropFunction · 0.85
isFunctionFunction · 0.85
cbFunction · 0.50

Tested by

no test coverage detected