I am writing code for the Firefox browser addon and I am trying to update the value of cookies using chrome API. While calling the chrome.cookies.set method, it returns the following error on the console.
Error: uncaught exception: unknown (can't convert to string)
var finalCookieObj = {
domain: ".qa.soul.com",
name: "aaa",
value: "as",
path: "/",
httpOnly: false,
url: "qa.soul.com/",
expirationDate: 1459788960
};
chrome.cookies.set(finalCookieObj, function(cookie) {
console.log('added cookie');
});
API reference: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/cookies/set
I think the problem is that url
needs to be a fully-qualified URL, including protocol. This version works:
var finalCookieObj = {
domain: ".qa.soul.com",
name: "aaa",
value: "as",
path: "/",
httpOnly: false,
url: "https://qa.soul.com/",
expirationDate: 1459788960
};
chrome.cookies.set(finalCookieObj, function(cookie) {
console.log('added cookie');
});
I'll update the docs to be explicit about this.
Also, asynchronous functions report errors by setting chrome.runtime.lastError: it's always a good idea to check this in your callback.
It's funny, though, I see different console output to you. I see an error like this:
[Exception... "Component returned failure code: 0x804b000a
(NS_ERROR_MALFORMED_URI) [nsIIOService.newURI]" nsresult:
"0x804b000a (NS_ERROR_MALFORMED_URI)" location: "JS frame
:: resource://gre/modules/NetUtil.jsm :: NetUtil_newURI ::
line 191" data: no]
... that includes a call stack containing NetUtil_newURI()
, that was enough to point to the url
as the problem. Which console are you looking at?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With