I'm attempting to retrieve a cookie from a specific website using a Chrome extension, but as someone who has never created one before, I'm facing some challenges. Despite reading numerous tutorials, I haven't been successful in capturing the cookie.
My approach involves using a content script, but I keep encountering an error message each time I try.
Here is the code for my manifest, content script, and the error:
manifest.json
...
"manifest_version": 3,
"permissions": [
"cookies"
],
"content_scripts": [{
"matches": ["*://google.com/"],
"js": ["content.js"]
}]
content.js
var ID;
function getCookies(domain, name) {
chrome.cookies.get({"url": domain, "name": name}, function(cookie) {
ID = cookie.value;
showId();
});
}
function showId() {
alert(ID);
}
getCookies("https://google.com/", "SSID");
Error:
Uncaught TypeError: Cannot read property 'get' of undefined
Any suggestions on how to resolve this issue would be greatly appreciated.