Access cookies with a Firefox Addon content script?

耗尽温柔 提交于 2019-12-08 05:18:56

问题


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?

Here's the original code:

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

回答1:


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.

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.



来源:https://stackoverflow.com/questions/16491966/access-cookies-with-a-firefox-addon-content-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!