问题描述
我的Chrome扩展在后台页面中使用jQuery,用于像 (铬);
_window = Cc [@ mozilla.org/appshell/appShellService;1]
.getService(Ci.nsIAppShellService)。hiddenDOMWindow;
$ = require('../ 3rdparty / jquery')(_ window);
然而,我不得不修补jQuery(2.1.3)本身,将行3441改为
window.setTimeout(jQuery.ready);
我相当有信心这是一个jQuery错误。
My Chrome extension makes use of jQuery in the background page, for things like jQuery.extend(), jQuery.ajax(), jQuery.deferred(), (not DOM manipulation stuff, which doesn't make sense in a background page).
Migrating this code to a Firefox SDK Add-on, there's no background window object, which jQuery requires to work, so something like
var $ = require('../3rdparty/jquery.min')(window);
which is how jQuery works in a CommonJS-like environment, fails, with jQuery itself throwing a jQuery requires a window with a document exception.
Is there any way to use jQuery in a Firefox SDK-based add-on? Page Workers seemed promising, but I can't get hold of the underlying window object.
Andy
This works:
var {Cc, Ci} = require("chrome"); _window = Cc["@mozilla.org/appshell/appShellService;1"] .getService(Ci.nsIAppShellService).hiddenDOMWindow; $ = require('../3rdparty/jquery')(_window);
However, I had to patch jQuery (2.1.3) itself, changing line 3441 to
window.setTimeout( jQuery.ready );
I'm reasonably confident this is a jQuery bug.
这篇关于将使用jQuery的Chrome扩展移植到Firefox SDK插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!