使用Firefox Addon内容脚本访问Cookie? [英] Access cookies with a Firefox Addon content script?

查看:208
本文介绍了使用Firefox Addon内容脚本访问Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从其他人创建的Chrome中翻译Addon。它有一个内容脚本,其中有 chrome.cookies.get 。我找不到一个合适的方法来解决这个Firefox。有什么方法可以从addon sdk中的内容脚本访问cookies吗?

I am trying to translate an Addon from Chrome that someone else created. It has a content script that has chrome.cookies.get in it. I can't find a suitable way to fix this for Firefox. Is there any way that I can access the cookies from a content script in the addon sdk?

这是原始代码:

function getCookies(domain, name, callback) {
    chrome.cookies.get({"url": domain, "name": name},
        function(cookie) {
            if (callback) {
                if (cookie) {
                        callback(cookie.value);
                } else {
                    callback(null);
                }
            }
        }
    );
}


推荐答案

拥有必要的权限,无需在Firefox或Chrome中使用任何高级API。它可以通过 document.cookie

A content script doesn't have the necessary privileges to use any advanced API - neither in Firefox nor in Chrome. It can get the cookies for the current page via document.cookie however. Same restrictions apply as for the web page itself - HTTPOnly cookies won't be visible.

在扩展模块中,您可以使用 nsICookieManager2 界面访问Cookie。请参阅在Firefox扩展程序中按域/名称访问特定的Cookie 详情。如果您想从内容脚本中获取该信息,您必须从内容脚本向扩展程序发送消息,以便扩展程序为您检索。

In the extension modules however you can use nsICookieManager2 interface to access cookies. See Access specific cookies by domain/name in Firefox extension for details. If you want that information from a content script you will have to send a message from the content script to the extension to make the extension retrieve it for you.

这篇关于使用Firefox Addon内容脚本访问Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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