user3827303
user3827303

Reputation: 429

How to read cookies from localhost?

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?

Upvotes: 5

Views: 1382

Answers (1)

user2864740
user2864740

Reputation: 61975

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

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

Upvotes: 2

Related Questions