I have the following firefox extension. I want to get cookies from the browser. But when I click “All” in the extension, the console.log(await (browser.cookies.getAll({}))
only print an array of zero length. I tried to compare with the following package, but I can not see what is the difference that causes the problem. How can I find out what causes the problem?
https://github.com/hrdl-github/cookies-txt
==> manifest.json <==
{
"manifest_version": 2,
"name": "DefaultPopup",
"version": "1.0",
"permissions": [
"downloads"
, "cookies"
],
"browser_action": {
"default_popup": "popup/choose_option.html"
},
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["runtime.js"]
}
]
}
==> background.js <==
browser.runtime.onInstalled.addListener(function(details) {
console.log('onInstalled');
console.log(details);
});
browser.runtime.onMessage.addListener(async function(details) {
console.log('onMessage');
console.log(details);
console.log(
await (browser.cookies.getAll({}))
);
});
==> runtime.js <==
console.log(browser)
/*
console.log(browser.downloads)
console.log(browser.runtime)
console.log(browser.runtime.id)
*/
==> popup/choose_option.html <==
<!DOCTYPE html>
<html>
<body>
<button class="all">All </button>
<script src="choose_option.js"></script>
</body>
</html>
==> popup/choose_option.js <==
document.querySelector(".all").addEventListener("click", () => {
console.log('click')
browser.runtime.sendMessage("my message");
window.close();
});