Set cookie manually in fetch

I need to fetch some page in my firefox extension scripts. The page to be fetched returns valid content only when where is a valid cookie passed.

I can fetch the cookies using browser.cookies API, but failed to set the cookie in the fetch request.

Desired

is there a way (I didn’t found) to make fetch automatically read the API, or allow set cookie manually ?

Hi.

There are two options to make such request.

  1. Tell fetch to include the cookies from the browser using the credentials init parameter. You can find some examples here.
  2. Another way is to set the cookies manually like I do in one of my add-ons to allow using cookies from non-default container/contextual identity. You can read about in an older topic.
  3. If it’s your API you have under control, you may try to switch from cookie-base authentication to some other HTTP header, that can be used for auth using some credentials or tokens supplied by the user.

I hope these options will help you. If that’s viable for you, I would recommend the first or the last one.