Greasemonkey, Chrome and unsafeWindow.foo()

筅森魡賤 提交于 2019-11-30 10:04:24

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");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!