如何使用Firefox 22+扩展程序删除跨网站Cookie? [英] How do I delete cross site cookies with Firefox 22+ extension?

查看:216
本文介绍了如何使用Firefox 22+扩展程序删除跨网站Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的Firefox扩展程序添加一个函数,以便在点击站点A上的按钮时触发事件以从站点B删除Cookie。站点A和B不共享域,但站点B在注入站点A的iframe中运行。我需要Firefox内容脚本中的单击事件,以在内容脚本或Firefox扩展主程序中触发事件,以删除所有来自网站B的Cookie。

I am attempting to add a function to my Firefox extension to trigger an event to delete cookies from site B when a button on site A is clicked. Site A and B do not share a domain but site B is running in an iframe injected into site A. I need the click event in the Firefox content script to trigger an event either in the content script or the Firefox extension main to delete all of the cookies from site B.

我将点击监听器分配给按钮并启动。我已经在Google Chrome中通过扩展程序实现了相同的效果。我得到一个关于使用组件的错误,但我找不到一个解决方案使用而不是组件。它只需要在Firefox 22+上工作。我使用addon-sdk-1.14来开发扩展。

I have the click listener assigned to the button and firing. I have already achieved this same effect in Google Chrome with an extension. I get an error about using components, but I could not find a solution to use instead of components. It only needs to work on Firefox 22+. I am using addon-sdk-1.14 to develop the extension.

ContentScript.js

ContentScript.js

function DeleteCookies() {
    var payload="Delete";
    self.port.emit("Delete", payload);
}

Main.js

var {Cc, Ci} = require("chrome");
pageMod.PageMod({
    include: "*",
    contentScriptFile: [ self.data.url("jquery-1.9.1.js")
                        ,self.data.url("script.js")],
    onAttach: function(worker) {
                  worker.port.on('Delete',function (){ DeleteCookies();});
              }
});

function DeleteCookies() {
    var cookieManager = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
    var domain= "siteB.com";
    var iter = cookieManager.enumerator;
    var cookie_count = 0;
    while (iter.hasMoreElements()) {
        var cookie = iter.getNext();
        if (cookie instanceof Ci.nsICookie) {
            if (domain.indexOf(cookie.host.toUpperCase()) != -1) {
                cookieManager.remove(cookie.host, cookie.name, cookie.path, cookie.blocked);
                cookie_count++;
            }
        }
    }
};


推荐答案

您无法从内容脚本访问XPCOM。使用端口机制,用于内容脚本和main.js之间的通信,并从后者删除cookie。

You can't access XPCOM from a content script. Use the port mechanism for communication between the content script and main.js, and do the cookie deletion from the latter.

这篇关于如何使用Firefox 22+扩展程序删除跨网站Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆