Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using chrome.browsingData.remove() in incognito mode

I have an extension removing the downloads made in Google Chrome using this line of code in my background page:

chrome.browsingData.remove({ "since": 0 }, { "downloads": true });

When a download is in a normal window it works however when a download has been made in an incognito Chrome window it is not removed. My extension is activated in incognito mode and the background page is able to detect when a download in the incognito page has been completed using:

chrome.downloads.onChanged.addListener(function(download) {
    if (download.state && download.state.current == "complete") {
        // The code here is fired even if the download has been completed in incognito mode
    }
}

Is there a way to remove the browsing data in incognito windows from a background page?

like image 817
Armand Grillet Avatar asked Sep 27 '22 17:09

Armand Grillet


1 Answers

The problem you're facing is that your extension is running in spanning incognito mode. This means that the extension runs under a single process attached to the profile that installed the extension (i.e. not the incognito window). In this situation, the chrome.downloads API fires the onChanged event for downloads in both incognito and normal profiles, but the chrome.browsingData API only applies to the normal profile.

Instead, you want to use split incognito mode. This means that the extension runs separately in each profile that uses it (i.e. the incognito window gets its own running copy of the extension). This means that when you call the chrome.browsingData API, it applies to the window that fired the event.

like image 125
Jim O'Brien Avatar answered Oct 27 '22 14:10

Jim O'Brien