Greasemonkey, Chrome and unsafeWindow.foo()

前端 未结 1 717
[愿得一人]
[愿得一人] 2021-01-01 01:37

I have the following anchor tag, which contains dynamically-generated arguments arg1,...,arg5 to the JavaScript function foo(), which runs on the w

相关标签:
1条回答
  • 2021-01-01 02:09

    In Chrome, you're not allowed to access variables/functions defined by the content page from the userscript context (see here).

    Instead of calling unsafeWindow.foo, you could just call candidate.onclick() in your loop.

    If that isn't what you want, you either have to inject the function call into the DOM using something like

    var s = document.createElement("script");
    s.innerHTML = "foo("+ script_args + ")";
    document.body.appendChild(s);
    

    or assign a JS-uri to location:

    location.assign("javascript:foo(" + script_args +");void 0");
    
    0 讨论(0)
提交回复
热议问题