0

varsa benChrome uzantıları API çerez

if (hostName == "google.com") { 
    chrome.runtime.sendMessage({greeting: "hello"}, function(response) { 
     console.log(response.farewell); 
     if (response.farewell == null) {console.log("cookie is 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; 
    } 
}); 

content.js kodu aşağıdaki ile krom uzantılı çerez kontrol etmeye çalışıyorum kontrol etmez Çerez ayarlanmışsa bu kod çalışır. Ancak çerez yoksa uyarı ve yanıt yoktur. Çerez olup olmadığını nasıl kontrol ederim? Neyi yanlış yapıyorum?

cevap

0

docs (here) orada bir çerez değil, bu yüzden cookie.value böyle arka plan sayfasında bir hata atma gerekip gerekmediğini cookienull olduğunu baktığımızda: Cannot read property 'value' of null. Belki de, mesaj yanıtınız yerine getCookies işlevinizde null sonucunu test etmeyi deneyin.

İlgili konular