diff --git a/qutebrowser/javascript/greasemonkey_wrapper.js b/qutebrowser/javascript/greasemonkey_wrapper.js index 2d36220dc..d9ea736df 100644 --- a/qutebrowser/javascript/greasemonkey_wrapper.js +++ b/qutebrowser/javascript/greasemonkey_wrapper.js @@ -110,6 +110,42 @@ } } + // Stub these two so that the gm4 polyfill script doesn't try to + // create broken versions as attributes of window. + function GM_getResourceText(caption, commandFunc, accessKey) { + console.error(`${GM_info.script.name} called unimplemented GM_getResourceText`); + } + + function GM_registerMenuCommand(caption, commandFunc, accessKey) { + console.error(`${GM_info.script.name} called unimplemented GM_registerMenuCommand`); + } + + // Mock the greasemonkey 4.0 async API. + const GM = {}; + GM.info = GM_info; + Object.entries({ + 'log': GM_log, + 'addStyle': GM_addStyle, + 'deleteValue': GM_deleteValue, + 'getValue': GM_getValue, + 'listValues': GM_listValues, + 'openInTab': GM_openInTab, + 'setValue': GM_setValue, + 'xmlHttpRequest': GM_xmlhttpRequest, + }).forEach(([newKey, old]) => { + if (old && (typeof GM[newKey] == 'undefined')) { + GM[newKey] = function(...args) { + return new Promise((resolve, reject) => { + try { + resolve(old(...args)); + } catch (e) { + reject(e); + } + }); + }; + } + }); + const unsafeWindow = window; // ====== The actual user script source ====== //