有没有办法启用Cookie,以便我可以使用page-worker API执行登录? 这是关于我的代码的样子:
var pageWorkers = require("sdk/page-worker");
pageWorkers.Page({
contentURL: asdasd.com/login.php?id=xxxxxx&pwd=yyyyyyy
contentScript: "self.postMessage(document.body.innerHTML)",
contentScriptWhen: "ready",
onMessage: function(msg) {
console.log(msg);
}
});
pageWorkers.Page({
contentURL: asdasd.com/site_that_is_only_visible_if_loged_in.php
contentScript: "self.postMessage(document.body.innerHTML)",
contentScriptWhen: "ready",
onMessage: function(msg) {
console.log(msg);
}
});
第二个console.log()告诉我,我没有进入。这就是为什么我假设登录的cookie没有保存。 如果我手动打开登录链接和firefox中的另一个链接,它可以正常工作。附加组件似乎无法做到。 :/
答案 0 :(得分:0)
您需要重复使用相同的PageWorker,而不是创建第二个:
var pagecount = 0;
var pageWorker = require("sdk/page-worker").Page({
contentURL: "http://asdasd.com/login.php?id=xxxxxx&pwd=yyyyyyy",
contentScript: "self.postMessage(document.body.innerHTML)",
contentScriptWhen: "ready",
onMessage: function(msg) {
console.log("html: "+msg);
if (++pagecount == 1)
loadSecondPage();
}
});
function loadSecondPage() {
pageWorker.contentURL =
"http://asdasd.com/site_that_is_only_visible_if_loged_in.php";
}