无法向firefox插件中的面板发送消息? (该页面当前已隐藏,在再次可见之前无法再使用)

时间:2013-03-13 17:45:15

标签: 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 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);

我还尝试再次打开面板或使用postMessage()代替。似乎什么都没有用,我无法将内容传回我的面板!任何帮助都是适当的!

这是我的main.js

var data = require("self").data;

var popup = require("panel").Panel({
  width: 212,
  height: 200,
  contentURL: data.url("popup.html"),
  contentScriptFile: [data.url("jquery.js"),data.url("popup.js")]
});

var Request = require("request").Request;

popup.port.on("handlelogin", function (url) {
    console.log("requesting " + url);
    var hosters = Request({
        url: url,
        onComplete: function (response) {       
            console.log(response.status);
            console.log("emmiting handleloginresponse");
            popup.port.emit("handleloginresponse",response);
        }
    }).get();
}); 

require("widget").Widget({
  label: "my label",
  id: "pop-up",
    contentURL: data.url("16.png"),
  panel: popup
});

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>

popup.js

$('#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);
});

1 个答案:

答案 0 :(得分:1)

问题已解决,因为服务器端http错误

导致该问题不存在