(parent, tag, attrs)
| 205 | } |
| 206 | |
| 207 | function 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 |
no test coverage detected