# Context identifier for popup/background pages

**URL:** <https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631>\
**Category:** Development\
**Created:** [February 3, 2019, 3:46pm UTC](https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631 "2019-02-03T15:46:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeenuv](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/jeenuv/32/23220_2.png) [@jeenuv](https://discourse.mozilla.org/u/jeenuv)\
**Post date:** [February 3, 2019, 3:46pm UTC](https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631/1 "2019-02-03T15:46:56Z")

</div>

Is there’s way I a could associate a context identifier with the browser action popup?

My reading of the API is that you specify a cookie store ID (which you query using a context ID) when you create a tab. For requests other than from a tab (popup, background scripts), I don’t find a way to associate context identifier.

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [February 3, 2019, 4:30pm UTC](https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631/2 "2019-02-03T16:30:02Z")

</div>

Your extension requests have their own context attached by default, so no cookies from the normal browsing context are sent.

---

<div class="post-metadata">

**Author:** ![jeenuv](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/jeenuv/32/23220_2.png) [@jeenuv](https://discourse.mozilla.org/u/jeenuv)\
**Post date:** [February 4, 2019, 8:10pm UTC](https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631/3 "2019-02-04T20:10:28Z")

</div>

I had a feeling that’d be the case. However, I’d ask user to login to their Google Account (my extension is bookmark-related), so I’d have to do that from a normal Google login page (rather than asking the user to hand over the username and password to the extension). At the same time, I don’t want that particular Google login to install cookies that would be visible to the default browsing session.

So my plan was–if at all possible–to associate the login page with a cookie store, and then re-use that cookie store later to sync bookmarks in the background etc.

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [February 4, 2019, 11:00pm UTC](https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631/4 "2019-02-04T23:00:20Z")

</div>

So this auth flow isn’t OAuth2 since you’re worrying about having access to the cookies later on?

---

<div class="post-metadata">

**Author:** ![jeenuv](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/jeenuv/32/23220_2.png) [@jeenuv](https://discourse.mozilla.org/u/jeenuv)\
**Post date:** [February 8, 2019, 6:33pm UTC](https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631/5 "2019-02-08T18:33:39Z")

</div>

Not at all. This is just the username/password login that the user does on the usual login page. Only that the extension would like to use the same credentials for future sync etc., and also keep the credentials to itself.

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [February 8, 2019, 6:35pm UTC](https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631/6 "2019-02-08T18:35:13Z")

</div>

I assume the problem here is that it involves sending cookies with your requests, since everything else would be doable. Make a temporary container where the user auths in and get the necessary credentials. Send credentials with requests, done.

---

<div class="post-metadata">

**Author:** ![jeenuv](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/jeenuv/32/23220_2.png) [@jeenuv](https://discourse.mozilla.org/u/jeenuv)\
**Post date:** [February 8, 2019, 8:08pm UTC](https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631/7 "2019-02-08T20:08:11Z")

</div>

Yes, I figured the getting the ‘user log in in a container tab’ part. What I don’t know is how to reuse that specific credentials when making requests form elsewhere within the extension (say, background page), at a later point in time–i.e., going back to my original question: associating the extension with a cookie store/context identifier other than the default.

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [February 8, 2019, 8:10pm UTC](https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631/8 "2019-02-08T20:10:15Z")

</div>

Yeah, sadly it seems like you’d have to do a lot of work to override the cookies for your requests. You can’t specify a cookie header from fetch, so you’d have to modify them with webRequest and that seems very tedious to me. And then you’d have to manually filter out the incoming cookie header and apply that to your cookie jar, so they don’t end up in the uncontained or whatever jar you have in an extension.

---

<div class="post-metadata">

**Author:** ![jeenuv](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/jeenuv/32/23220_2.png) [@jeenuv](https://discourse.mozilla.org/u/jeenuv)\
**Post date:** [February 9, 2019, 11:16am UTC](https://discourse.mozilla.org/t/context-identifier-for-popup-background-pages/35631/9 "2019-02-09T11:16:01Z")

</div>

Sigh… that confirms my inkling. Thanks.
