Unhandled exception: unknown (cannot be converted to string)

I am writing code for a Firefox browser addon and I am trying to update a cookie using the chrome API. By calling the chrome.cookies.set method, it returns the following error on the console.

Error: uncaught exception: unknown (cannot 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 Link: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/cookies/set

+5
source share
1 answer

I think the problem is that the url should be a fully qualified URL, including the 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 am updating documents to be explicit.

In addition, asynchronous functions report errors by setting chrome.runtime.lastError : it is always useful to check this in your callback.

Funny, however, I see another console output for you. I see an error:

 [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] 

... which includes a call stack containing NetUtil_newURI() , this was enough to point to the url as a problem. What console are you looking at?

+2
source

Source: https://habr.com/ru/post/1246345/


All Articles