3

I'm trying to create Chrome extension for managing cookies I've created this simple code for this

manifest.json

{
    "name" : "cookie_tester",
    "version" : "0.1",
    "description" : "Tool for cookie mechanism",
    "permissions": [ "cookies", "tabs", "activeTab", "storage", "<all_urls>"],
        "icons": { 
            "128": "icon.png" 
            },

    "page_action": {
      "default_icon": {
            "128": "icon.png" 
      },
      "default_title":"cookie_tester"      
    },


    "background": {
    "scripts": ["background.js"],
    "persistent": false
    },
    "manifest_version": 2
}

background.js is here https://pastebin.com/raw/YpQRqvZr

So when I activate incognito window and click on extension icon: the cookie isn't created. cookie wasn't created

Of course I've allowed this extension to work in incognito mode allow in incognito Could you please help me to find out the reason? Chrome version is Version Version 71.0.3578.80 (Official Build) (64-bit) Thanks in advance

dvrs
  • 93
  • 6
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – wOxxOm Dec 12 '18 at 07:09
  • Callbacks in chrome extension API are always invoked asynchronously. It's basically like a one-time event listener that's invoked at a later time so the function itself returns nothing, it simply tells Chrome "invoke this callback later when the data is ready" and exits immediately. See the linked thread for solutions. You can also use https://github.com/mozilla/webextension-polyfill – wOxxOm Dec 12 '18 at 07:10
  • Thanks @wOxxOm I've changed my code and got another issue, Updated the answer – dvrs Dec 12 '18 at 09:09
  • Maybe [Chrome Extension in incognito mode](//stackoverflow.com/q/43994676) or you need to specify [`storeId` property](https://developer.chrome.com/extensions/cookies#type-Cookie) when using chrome.cookies API. – wOxxOm Dec 12 '18 at 09:56
  • @wOxxOm incognito key is what I needed – dvrs Dec 12 '18 at 11:18

1 Answers1

3

Thanks @wOxxOm Yep, when I've added incognito key into mainfest with value "split" I've finally got working result!

Updated manifest.js

{
  "name" : "cookie_tester",
  "version" : "0.1",
  "description" : "Tool for cookie mechanism ",
  "permissions": [ "cookies", "tabs", "activeTab", "storage", "<all_urls>"],
  "icons": { 
                "128": "icon.png" 
                },

        "page_action": {
          "default_icon": {
                "128": "icon.png" 
          },
          "default_title":"cookie_tester"      
        },


  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },

  "manifest_version": 2,
  "incognito": "split"
}
dvrs
  • 93
  • 6
  • Can we make it work in {"incognito": "spanning"}? I can't use split incognito mode for my extension. – Manoj May 22 '23 at 12:20