4

I'm trying to develop a Chrome Extension, and the first step is to determine whether the user is logged into my website. For development, I'm testing against localhost, so how do I read the write cookies?

Here's what's in my manifest:

"permissions": [
    "cookies", "tabs", "http://*/*", "https://*/*"
],

And the JavaScript is:

chrome.cookies.get({"url": 'localhost', "name": '_ga'}, function(cookie) {
    console.log('cookie:');
    console.log(cookie);
}); 

But I get this error:

Unchecked runtime.lastError while running cookies.get: Invalid url: "localhost".

Can anyone point me in the right direction?

1
  • Ah, that was the problem. Please post as the answer so I can accept! :) Nov 4, 2014 at 23:56

1 Answer 1

2

localhost is not a valid URL; it is merely a [perceived] host name.

Use http://localhost, with the protocol included, for the URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.