Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught exception: unknown (can't convert to string)

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

like image 904
sfbayman Avatar asked Oct 30 '22 06:10

sfbayman


1 Answers

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?

like image 175
wbamberg Avatar answered Nov 14 '22 22:11

wbamberg