Send XHR request from Chrome extension with cookies

I'm trying to send an XHR request from a Google Chrome extension to another domain. This would work fine, but I need to send that domains cookies with the request. Any way to do this?

Answers


Make sure the manifest.json permissions are setup properly.

You have to properly set the cross site domain request permission in the manifest.json of your chrome extension. When done properly, the cookies who are already set for the targeted domain will be sent along with the request you are making to that domain. manifest.json documentation

You have to be especially careful when playing with localhost:port_number. You will need to specify that domain in full in the manifest.json for it to work. I ended up with awkward behaviors when my localhost domain was NOT specify in full.

This is how you want to specify your localhost domain in the manifest.json of your extension (if that makes sense):

...
"permissions": [
    "http://localhost:3000/"
  ],
...

If the cookies you want to send to the targeted domain are not set yet, you can do so my using the chrome.cookies.set method and specify the domain name you want through the object domain attribute you pass to the set method. The documentation is here: chrome.cookies.set.


Need Your Help

Run a file from a different directory in Windows 7 cmd?

laravel cmd directory phpunit

My question is similar as this one. But the answers to it don't help

Buffered Output Writing to File Wrong

java file file-io buffered

I can't figure it out. I'm trying to write out text from my program. It's suppose to a word count program. Show me the number of lines, characters, word count. Then I display the results along with...