Discussies » Ontwikkeling

Tampermonkey run-at document-start is too slow.

§
Geplaatst: 15-06-2017
Bijgewerkt: 15-06-2017

Tampermonkey run-at document-start is too slow.

Long story short, in Tampermonkey if you set the run-at metadata key to document-start the userscript will begin execution after the entire HTML <head> element has loaded. The problem is that the page I have the userscript running on has a script element in the head that changes global functions like console.log, console.error, etc, that the wrapper in Tampermonkey itself uses. (Userscripts in Tampermonkey are 'wrapped' in code that looks like:)

(function () {
    (function (context, fapply, console) {
        with(context) {
            (function (module) {
                "use strict";
                try {
                    fapply(module, context, [, , context.CDATA, context.uneval, context.define, context.module, context.GM_info]);
                } catch (e) {
                    if (e.message && e.stack) {
                        console.error("ERROR: Execution of script 'Agar.io Plus' failed! " + e.message);
                        console.log(e.stack.replace(/(\\(eval at )?<anonymous>[: ]?)|([\s.]*at Object.tms_[\s\S.]*)/g, ""));
                    } else {
                        console.error(e);
                    }
                }
            })(function (context, fapply, CDATA, uneval, define, module, GM_info) {

                // ==UserScript==
                // ==/UserScript==

            })
        }
    })(this.context, this.fapply, this.console)
})
.apply(window["__u__5180244.554394921_"])

As you can see, this wrapper makes use of global functions, but after they're already changed by the page. If the page wanted to, they could break ALL Tampermonkey userscripts outright.

Solutions? Does Greasemonkey for Firefox do this?

woxxomMod
§
Geplaatst: 15-06-2017
Bijgewerkt: 15-06-2017

Ask the TM's developer on their forum or github repo. If done properly, a sandboxed userscript (the one that doesn't have @grant none) should use DOM classes, methods, standard JS functions from the extension's content script context, which is executed by the browser in an isolated world, meaning the page can't overwrite any of its methods.

P.S. we can try summonning @derjanb here though. P.P.S. see also https://github.com/Tampermonkey/tampermonkey/issues/211

Reactie plaatsen

Log in om antwoord te geven.