| 9 | addEventListener(ERROR, e => showUnhandledError(e.error)); |
| 10 | addEventListener('unhandledrejection', e => showUnhandledError(e.reason)); |
| 11 | export function showUnhandledError(err) { |
| 12 | if (!err) return; |
| 13 | const id = 'unhandledError'; |
| 14 | const fontSize = 10; |
| 15 | const el = document.getElementById(id) || document.createElement('textarea'); |
| 16 | const text = el.value = [ |
| 17 | el.value, |
| 18 | isObject(err) |
| 19 | ? `${IS_FIREFOX && err.message || ''}\n${err.stack || ''}` |
| 20 | : `${err}`, |
| 21 | ]::trueJoin('\n\n').trim().split(extensionRoot).join(''); |
| 22 | const height = fontSize * (calcRows(text) + 1) + 'px'; |
| 23 | const parent = document.body || document.documentElement; |
| 24 | el.id = id; |
| 25 | el.readOnly = true; |
| 26 | // using an inline style because we don't know if our CSS is loaded at this stage |
| 27 | el.style.cssText = `\ |
| 28 | position:fixed; |
| 29 | z-index:${1e9}; |
| 30 | left:0; |
| 31 | right:0; |
| 32 | bottom:0; |
| 33 | background:#000; |
| 34 | color:red; |
| 35 | padding: ${fontSize / 2}px; |
| 36 | font-size: ${fontSize}px; |
| 37 | line-height: 1; |
| 38 | box-sizing: border-box; |
| 39 | height: ${height}; |
| 40 | border: none; |
| 41 | resize: none; |
| 42 | `.replace(/;/g, '!important;'); |
| 43 | el.spellcheck = false; |
| 44 | el.onclick = () => el.select(); |
| 45 | parent.style.minHeight = height; |
| 46 | parent.appendChild(el); |
| 47 | } |
| 48 | |
| 49 | export function showMessage(message) { |
| 50 | const modal = Modal.show(() => h(Message, { |