My chrome extensions Content script uses a chrome.runtime.sendMessage to send a message to my Background script, which then needs to read the cookies and return these in the 'sendResponse'.. code below:
ContentScript.js
chrome.runtime.sendMessage({getcookies: "Get me cookies"}, function (response){
console.log(response.cookieList);
});
BackgroundScript.js
var cookiesFinal;
chrome.runtime.onMessage.addListener(function(res, sender, sendResponse) {
chrome.cookies.get({ url: 'https://www.example.com/', name: 'cookie1' }, function GetCookies(cookies) {
cookiesFinal = cookies;
});
sendResponse(cookiesList: cookiesFinal);
});
However when I run this I get an error saying 'cannot read value of cookieList: undefined?
Any tips on how I can make this work?