Adding a @grant value breaks my Greasemonkey+jQuery script?

♀尐吖头ヾ 提交于 2019-11-29 14:12:24
Brock Adams

See "Error: Permission denied to access property 'handler'".

You can no longer invoke the target-page's jQuery like that.

(Note that in @grant none mode (the default as of GM 2), unsafeWindow is the same as window... But, then you can't use GM_ functions.)


@require your own copy of jQuery; it will not conflict with the page's and will load faster, to boot.

Do not use unsafeWindow for things like this (or at all, if you can help it), and $(document).ready() is also almost never needed for Greasemonkey scripts.

Your (new) sample script would merely be:

// ==UserScript==
// @name        Dimi Test
// @namespace   Dimi
// @version     1
// @grant       GM_xmlhttpRequest
// @include     about:addons
// @include     http://*.myDomain.*/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// ==/UserScript==

$("body").prepend ('<h1>Hello World!</h1>');

And you can then mix GM_ functions and your instance of jQuery with no problems.



Note: The question script has // @include about:addons.
Greasemonkey scripts will not work on the about:addons page, by design.

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