访问content.js中的cookie
chrome.runtime.sendMessage(
{
type: "getAllCookies",
data: {}
},
function callback(cookies) {
console.log(cookies);
}
);
background.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
switch (request.type) {
case "getAllCookies":
chrome.cookies.getAll(
{
domain: "xxx"
},
function(cookies) {
sendResponse(cookies);
}
);
break;
}
});
回调返回未定义,控制台显示以下错误
Unchecked runtime.lastError: The message port closed before a response was received.
Chrome版本:75.0.3770.100 x64
如何访问Chrome扩展程序中的Cookie?