javascript - Chrome extensions api doesn't check if cookie exists -


i'm trying check cookie chrome extension following code

content.js

if (hostname == "google.com") {     chrome.runtime.sendmessage({greeting: "hello"}, function(response) {         console.log(response.farewell);         if (response.farewell == null) {console.log("cookie null");}      }); } 

background.js

function getcookies(domain, name, callback) {     chrome.cookies.get({"url": domain, "name": name}, function(cookie) {         if(callback) {             callback(cookie.value);         }     }); }  chrome.runtime.onmessage.addlistener(function(message, sender, sendresponse) {     if (message.greeting == "hello") {         getcookies("http://www.google.com", "cookie_name", function(id) {             if (id) {                 alert("cookie "+id);                 sendresponse({farewell: id});             } else {                 alert("cookie "+id);                 sendresponse({farewell: id});             }         });         return true;     } }); 

this code works if cookie set. there no alert , response if there no cookie. how check if there no cookie? doing wrong?

looking @ docs (here) cookie null if there isn't cookie, cookie.value should throwing error in background page this: cannot read property 'value' of null. perhaps try testing null result in getcookies function rather in message response.


Comments