Javascript 无法向firefox插件中的面板发送消息?(页面当前处于隐藏状态,在再次可见之前无法再使用)
我的目标很简单:我想要一个面板,用户可以在其中指定用户名和密码,然后单击登录。然后我要执行webrequest来验证凭据,并向用户显示响应 我发现我必须在main.js中执行请求并将其传回。 因此,当提交表单时,我构建我的url,向main.js发送一条消息,在那里执行请求。这很好,反应也是正确的。 但是,当我想将响应发送回面板时,会出现以下错误:Javascript 无法向firefox插件中的面板发送消息?(页面当前处于隐藏状态,在再次可见之前无法再使用),javascript,firefox,firefox-addon,firefox-addon-sdk,Javascript,Firefox,Firefox Addon,Firefox Addon Sdk,我的目标很简单:我想要一个面板,用户可以在其中指定用户名和密码,然后单击登录。然后我要执行webrequest来验证凭据,并向用户显示响应 我发现我必须在main.js中执行请求并将其传回。 因此,当提交表单时,我构建我的url,向main.js发送一条消息,在那里执行请求。这很好,反应也是正确的。 但是,当我想将响应发送回面板时,会出现以下错误: Error: The page is currently hidden and can no longer be used until it is
Error: The page is currently hidden and can no longer be used until it is visible again.
resource://jid1-aaautmtqen7pta-at-jetpack/addon-sdk/lib/sdk/content/worker.js 404
Traceback (most recent call last):
File "resource://jid1-aaautmtqen7pta-at-jetpack/addon-sdk/lib/sdk/net/xhr.js", line 126, in
self._orsc.apply(self, arguments);
File "resource://jid1-aaautmtqen7pta-at-jetpack/addon-sdk/lib/sdk/request.js", line 91, in onreadystatechange
emit(target, 'complete', response);
File "resource://jid1-aaautmtqen7pta-at-jetpack/addon-sdk/lib/sdk/event/core.js", line 83, in emit
for each (let item in emit.lazy.apply(emit.lazy, arguments)) {
File "resource://jid1-aaautmtqen7pta-at-jetpack/addon-sdk/lib/sdk/event/core.js", line 101, in lazy
yield listeners.shift().apply(target, args);
File "resource://jid1-aaautmtqen7pta-at-jetpack/domain/lib/main.js", line 21, in hosters<.onComplete
popup.port.emit("handleloginresponse",response);
File "resource://jid1-aaautmtqen7pta-at-jetpack/addon-sdk/lib/sdk/content/worker.js", line 369, in
emit: function () self._emitEventToContent(Array.slice(arguments))
File "resource://jid1-aaautmtqen7pta-at-jetpack/addon-sdk/lib/sdk/content/worker.js", line 404, in _emitEventToContent
throw new Error(ERR_FROZEN);
popup.html
<html>
<head>
</head>
<body>
<form id="loginform">
<input name="user" placeholder="User" id="userfield" />
<input type="password" name="pass" placeholder="Password" id="passfield"/>
<input type="submit" id="loginbutton" value="Log in " />
</form>
</body>
</html>
问题本身解决为不存在,是由于服务器端http错误造成的结果表明,在我的情况下,这是不必要的,因为可以在main.js之外执行ajax请求,但是在我的尝试中,它不起作用,因为目标url传递了错误,并且我没有收到成功回调。因此我认为它不起作用。。。
<html>
<head>
</head>
<body>
<form id="loginform">
<input name="user" placeholder="User" id="userfield" />
<input type="password" name="pass" placeholder="Password" id="passfield"/>
<input type="submit" id="loginbutton" value="Log in " />
</form>
</body>
</html>
$('#loginform').submit(function (event) {
var url = 'https://mydomain.com?user=' + encodeURIComponent($('#loginform')[0].user.value) + '&pass=' + encodeURIComponent($('#loginform')[0].pass.value) + '&something=something;
self.port.emit("handlelogin",url);
});
self.on("handleloginresponse", function(data) {
console.log("got a handleloginresponse!");
console.log(data);
});