1

Basically, I'm trying to make an extension which on first install it clears cookies on a specific domain.

background.js:

chrome.runtime.onInstalled.addListener(function() {
    chrome.cookies.getAll({
        domain: "mydomain"
    }, function(cookies) {
        for (var i = 0; i < cookies.length; i++) {
            chrome.cookies.remove({
                url: "mydomain" + cookies[i].path,
                name: cookies[i].name
            });
        }
    });
});

however, this perfectly works only on default mode (non-incognito Google Chrome's mode); why? What's the actual problem? How can I make it work on incognito mode too?

WayneXMayersX
  • 338
  • 2
  • 10
  • 1
    [Content scripts](https://developer.chrome.com/extensions/content_scripts.html) can access only several chrome.* API. You'll need a popup/background/event page. – wOxxOm Apr 13 '17 at 11:28
  • @wOxxOm I already have a background page. – WayneXMayersX Apr 13 '17 at 11:30
  • @wOxxOm not that good when it doesn't even work when put in background. – WayneXMayersX Apr 13 '17 at 13:38
  • @wOxxOm you are correct. The problem was the incognito mode, which seems to use a separated cookies store. I used the non-incognito mode and the extension worked; is there a way to remove cookies from the website when I'm running the incognito mode? – WayneXMayersX Apr 13 '17 at 13:58
  • I don't know and the documentation doesn't seem to describe a way so it's apparently not possible. – wOxxOm Apr 13 '17 at 14:13
  • I'll wait for a @Makyen's reply. – WayneXMayersX Apr 13 '17 at 14:13
  • @WayneXMayersX, FYI: If a user hasn't interacted with the post, then using `@username` does not actually notify them. I only saw this while going through questions. I'm not sure what type of reply you're waiting for from me. If you have code which is functional, in normal mode, please update your question to be about that code and having it work in incognito mode. Right now, we have to address the question as written, which is about using `chrome.cookies` in a content script, which would be a duplicate ([chrome.tabs returns undefined in content script](http://stackoverflow.com/a/40682156)). – Makyen Apr 13 '17 at 16:59
  • Please also include a *manifest.json*. A [mcve] is required because *we want to help*. It is **much** easier to help if we don't have to recreate any of the code needed to duplicate the issue. This is code you already have. So, please help us to help you and provide a *complete* [mcve] that duplicates the problem. Without a [mcve], the amount of effort required to even begin to help you is **much** higher, which *significantly* reduces the number of people willing/able to help you. Even if we put out the extra effort, we have to **guess** at significant portions of what your problem might be. – Makyen Apr 13 '17 at 17:01
  • @Makyen fixed, my friend. :) – WayneXMayersX Apr 13 '17 at 18:09
  • @WayneXMayersX, Please include a *manifest.json*. While we can *guess* at what the *manifest.json* should include, we can't the setting wrt. [`incognito`](https://developer.chrome.com/extensions/manifest/incognito) key. Please also describe *exactly* the user interaction wrt. loading your extension. When I try to open `chrome://extensions/`, even when the only window is incognito, a new non-incognito window is opened, which is active when an extension is loaded from "Load unpacked extension". Also, how are you expecting it to be already enabled for incognito upon install? – Makyen Apr 13 '17 at 19:15

0 Answers0