Specify context (container) AJAX or fetch()

Hi.

Is it possible to specify container/context/cookieStoreId to use cookies from for XMLHttpRequest or fetch() from the add-on background script? The only “dirty” hack I have come to so far is to open a tab in that container, load the data there, and close it again.

Michal

1 Like

The other dirty hack is to change the cookie store with webRequest. But I think generally the background script can’t send the request for a specific cookie store.

Thank you Martin. Since yesterday I started digging deeper in parallel and I have found the cookies API. If I understand its capabilities correctly, it should allow me to query for cookies for a particular domain via getAll().

The question is, whether the storeId is compatible with the cookieStoreId from contextualIdentitities API. If so, it should be possible to add them manually to the add-on request via webRequest.onBeforeSendHeaders. First I thought it would be possible to add them manually to via fetch() or XMLHttpRequest, but I realized cookies cannot be set like other headers… :frowning:

yes, the cookieStoreId corresponds to the storeId from the cookies API.

Did you manage to find a solution for this?

The solution (or workaround) was to add onBeforeSendHeaders listener where the request can be modified and proper cookies (stolen from the right container) added. You can check https://github.com/MikkCZ/pontoon-addon/pull/88/files to get the basic idea.

3 Likes

Thanks Michal, this should be enough to get this working!