Getting cookies in a google chrome extension

后端 未结 2 1067
名媛妹妹
名媛妹妹 2020-12-24 15:04

I am trying to get a cookie specifically from a domain using this code:



        
2条回答
  •  [愿得一人]
    2020-12-24 15:22

    Almost all Chrome API calls are asynchronous, so you need to use callbacks to run code in order:

    function getCookies(domain, name, callback) {
        chrome.cookies.get({"url": domain, "name": name}, function(cookie) {
            if(callback) {
                callback(cookie.value);
            }
        });
    }
    
    //usage:
    getCookies("http://www.example.com", "id", function(id) {
        alert(id);
    });
    

提交回复
热议问题