Chrome Extension in incognito mode
Asked Answered
A

3

5

I have an extension for Chrome that makes ajax request to my site. The site uses sessions. So, in response of the ajax request to the site, the Set-Cookie header is returned with some session identifier and a this entry appears in the cookie section of the extension DevPanel (of the backgroud page). But, session id in the DevPanel browser for the site is a completely different. Extension is allowed for incognito mode.

In normal mode, the cookies are identical in the DevPanels of the extension and the browser. I understand that cookies for normal and incognito modes should be different, but why are these values ​​different for the extension allowed for incognito mode?

Am I right and extensions allowed for incognito mode, work in normal mode?

Angloindian answered 16/5, 2017 at 7:10 Comment(0)
A
8

The solution was suggested to me in the chrome discussion group.

There is a key "incognito" in extension manifest with three values: "spanning" (default), "split" and "not_allowed".

More about this key you can read here: https://developer.chrome.com/extensions/manifest/incognito.

To solve my problem it was enough to set value "split" for this key. In this case are opened two separate processes for extension - for normal and for incognito modes. If browser is opened in incognito mode, then the "incognito" extension process will be used.

And now, ajax requests in incognito mode get right session cookie.

P.S. If you're developing crossbrowser extension, note, that Firefox still (today: 2017-12-11) supports only "spanning" value for "incognito" key.

Angloindian answered 23/5, 2017 at 10:35 Comment(0)
W
2

You may refer with this thread. Be noted that if they are browser and web-browsing related items, like cookies and session data, then it's not possible to allow cookies in Incognito Mode.

When starting the first Incognito window, it uses a completely brand new and blank internal profile that has no cookies nor session data. Any cookies or session info are set immediately during that session. Further Incognito windows opened all share that same session, so they share the cookies/session data. But when the last Incognito window is closed all those cookies/session data is purged. None of the information is permanently saved.

And none of it can alter session info in Normal windows, because the Incognito windows run in a completely separate session.

This is per design and functionality of Incognito Mode.

Winther answered 16/5, 2017 at 16:42 Comment(1)
I understand and mostly agree with it. But if I open the Chrome browser initially in incognito mode (not switch from normal mode) with my extension already allowed for incognito mode, the cookies are again different. Session cookies created in chrome.browserAction.onClicked handler.Angloindian
C
2

Just add this to your manifest.json file

{
  "name": "Test",
  "version": "0.1",
  "description": "Tester",
  "manifest_version": 2,
   "incognito": "split" // add this line
}

Read more about the incognito options in the official docs

Crapulent answered 6/6, 2019 at 12:12 Comment(1)
How to do in manifest version 3?Florella

© 2022 - 2024 — McMap. All rights reserved.