Send XHR request with Chrome extension using cookies

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

+6
source share
1 answer

Make sure manifest.json permissions are configured correctly .

You must correctly set the permission to query the cross-site domain name in manifest.json your chrome extension. When everything is done correctly, cookies that are already configured for the target domain will be sent along with the request that you make in this domain. manifest.json documentation

You should be especially careful when playing with localhost:port_number . You will need to specify this domain fully in manifest.json for it to work. I ended up with inconvenient behavior when my localhost domain was not fully specified.

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

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

If the cookies you want to send to the target domain are not already set, you can do this using the chrome.cookies.set method and specify the domain name that you want through the domain attribute of the object that you pass to the set method. The documentation is here: chrome.cookies.set .

+5
source

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


All Articles