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

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

问题描述

我有一个 Firefox 的greasemonkey 脚本,昨天运行良好.我今天尝试使用它(没有修改代码),我注意到它停止工作.经过进一步检查,该脚本现在抛出以下错误:

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
});

当脚本昨天运行良好时,今天神奇地开始发生此错误.我不明白为什么在尝试执行一些基本操作(例如在 jQuery 中添加事件处理程序)时会发生此错误.

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.

我的脚本使用 jQuery,该脚本已在执行脚本的页面中使用,因此我使用此代码使其可供 GM 访问:

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;

如果需要,作为参考,以下是我在脚本中使用的以下 Greasemonkey 函数:

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

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

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 刚刚推送到所有设置为自动更新的 Firefox 浏览器.(GM 2 于 2014 年 6 月 17 日发布,但可能需要几周时间才能完成审核过程.)

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 彻底改变了unsafeWindow 处理:

向后不兼容更改:

  • 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.

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

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 是一个特例,来回克隆它会破坏事情.
@require jQuery 代替,EG:

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天全站免登陆