The following code doesn’t work for some reason:
Background.js
alert("1");
chrome.cookies.set({ url: "https://mywebsite.com", name: "SuperDuperTest" });
alert("2");
manifest.json
“permissions”: [ “notifications”, “https://mywebsite.com“,
“cookies”, “http://* /* “, “https://* / * ” ],
Only alert(“1”); ever fires. Alert 2 never does, why isn’t my chrome cookies firing at all?
Where are looking to check whether your cookie is set or not?
Please use
console.log()instead ofalert()Sample Code
manifest.json
Registered background page and given permissions for Cookies API.
background.js
Trivial code to set cookie for
cookies.htmlpageOutput
Go to https://developer.chrome.com/extensions/cookies.html and open developer tools as shown here, you can see cookie is being set!.
Click for Large Image
Further Debugging
If this sample code does not work, what are values of
chrome.extension.lastErrorandchrome.runtime.lastError?