错误:权限被拒绝访问属性“处理程序” [英] Error: Permission denied to access property 'handler'

查看:153
本文介绍了错误:权限被拒绝访问属性“处理程序”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Firefox的greasemonkey脚本,昨天工作完美。我今天尝试使用它(没有代码被修改),我注意到它停止工作。进一步检查后,脚本现在抛出以下错误:

 错误:权限被拒绝访问属性'处理程序'

这个错误在下面的代码块中被抛出:

click(function(){
// code here
));

这个错误在今天发生了,当时脚本昨天工作得很好。我不明白为什么这个错误发生时,只是试图做一些如此基本的事情,如在jQuery中添加一个事件处理程序。

我的脚本使用jQuery已经是在脚本执行的页面中使用,所以我使用这个代码使其可以访问GM:

  var $ = unsafeWindow。 jQuery的; 

如果需要,请参考下面的Greasemonkey函数:

  // @grant GM_getResourceText 
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_getResourceURL

我试过研究这个错误,我找不到任何答案。所有看起来可能有用的问题都涉及iframe,并且在我的代码或运行的网站中没有找到一个iframe。我也尝试删除并重新安装脚本,并没有解决问题。

解决方案

Greasemonkey 2.0只是被推送到设置为自动更新的所有Firefox浏览器。 (GM 2于2014年6月17日发布,但可能需要几个星期的时间才能完成审核过程。)

unsafeWindow 处理 rel =nofollow noreferrer / b>


向后不兼容更改:


通常,要点访问页面函数或变量,你可以切换到新的方法,但在你的情况下,你正在使用 var $ = unsafeWindow.jQuery; - 这是一个不好的做法。
$ b

jQuery是一种特殊情况,并且来回克隆会破坏事物。

@require jQuery代替,EG:

  // == UserScript == 
// @name _YOUR_SCRIPT_NAME
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http:// ajax。 googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_getResourceURL
// == / UserScript ==
...


I have a greasemonkey script for Firefox, which yesterday was working perfectly. I tried using it today (no code was modified) and I noticed that it stopped working. Upon further inspection, the script is now throwing the following error:

Error: Permission denied to access property 'handler'

This error is being thrown in the following block of code:

$('body').click(function() {
    // code here
});

This error magically started happening today when the script was working just fine yesterday. I'm not understanding why this error is happening when just trying to do something so basic such as adding an event handler in jQuery.

My script uses jQuery which is already being used in the page the script executes on, so I used this code to make it accessible to GM:

var $ = unsafeWindow.jQuery;

For reference if need be, here are the following Greasemonkey functions I use in my script:

// @grant       GM_getResourceText
// @grant       GM_addStyle
// @grant       GM_xmlhttpRequest
// @grant       GM_getResourceURL

I have tried researching this error and I can't find any answer. All of the questions that look like they might be helpful involve iframes and there is not a single iframe to be found in my code or the website it's run on. I've also tried deleting and re-installing the script and that didn't fix the problem.

解决方案

Greasemonkey 2.0 has just been pushed to all Firefox browsers set to auto-update. (GM 2 was released on June 17, 2014, but it can take a few weeks to get through the review process.)

Greasemonkey 2.0 radically changed unsafeWindow handling:

Backwards incompatible changes:

  • For stability, reliability, and security the privileged sandbox has been updated to match the new changes to unsafeWindow for the Add-on SDK. In order to write values to unsafeWindow you will need to use the new methods cloneInto(), exportFunction(), and/or createObjectIn().
  • The @grant none mode is now the default, and grants will no longer be implied when not explicitly provided. See the post Sandbox API Changes in Greasemonkey 2.0 for more detail.

Ordinarily, to spot-access a page function or variable, you could switch to the new methods but, in your case you are using var $ = unsafeWindow.jQuery; -- which was always a bad practice.

jQuery is a special case and cloning it back and forth is going to break things.
@require jQuery instead, EG:

// ==UserScript==
// @name        _YOUR_SCRIPT_NAME
// @include     http://YOUR_SERVER.COM/YOUR_PATH/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant       GM_getResourceText
// @grant       GM_addStyle
// @grant       GM_xmlhttpRequest
// @grant       GM_getResourceURL
// ==/UserScript==
...

这篇关于错误:权限被拒绝访问属性“处理程序”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆