Send cookies using ajax call from chrome script extension contents

I am making a chrome extension for a site on which the api checks whether the user has been subscribed or not. Api is for GET request. So when I don’t sing in it, it gives.

{ status: "ok", authenticated: false}

When I enter it, he gives me

{status : "ok", authenticated: true, id: 123}

This works great in browser, chrome extensions such as postman and advanced leisure client. But when I use it against my background of the chrome extension, it always says that I am not an authenticated user. I realized that the ajax call I am making does not send cookies for the domain, but a chrome extension like Postman or Advanced REST sends the cookies along with the XHR request.

Any idea how I can make ajax to send cookies along with it.

here is my ajax call from chrome extension

$.ajax({
    method:"GET",
    //  xhrFields: {
       //   withCredentials: true
       // },
       // crossDomain: true,
        url:"http://test-staging.herokuapp.com/user/details",
        success: function(result){
          if(result.status=="ok"){
            alert(JSON.stringify(result));
        cb(result.authenticated);
      }
    },
    error: function(err){
      alert("unable to authenticate user "+JSON.stringify(err))
    }
  })

1:

cookie script. , cookie ajax?

+4

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


All Articles