Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when another Chrome Extension overrides the same page

An example would be if my extension overrides the newtab page and the user installs another extension that also overrides the newtab page. Currently, only one newtab extension shows up and it usually isn't mine.

What can I do to detect when such a conflict occurs and inform the user of such?

The management API doesn't tell me if the extensions override any pages, so I sadly can't use that.

like image 245
St. John Johnson Avatar asked Oct 03 '22 11:10

St. John Johnson


1 Answers

This doesn't seem to be an exant feature of the API. I'd suggest you open a bug at http://crbug.com.

Failing that, you can perform the following nasty hack (which I haven't tested):

  1. Have your new tab page send a message to your background page whenever it loads.

  2. Listen for chrome.webNavigation.onBeforeNavigate events that deal with chrome://newtab:

    chrome.webNavigation.onBeforeNavigate.addListener(function(details) {
        /* send message */
    }, { url: [{ urlEquals: 'chrome://newtab/' }] });
    
  3. When webNavigation sees the browser load chrome://newtab but you don't see a message to your background page shortly afterwards, your new tab page is probably not being used. From there, you can send a notification, or open another tab/window with a notice.

Unfortunately, this requires the webNavigation permission, which is unfortunate if your extension doesn't otherwise need it. The warning that it carries ("This extension can access your tabs and browsing activity") might scare away some potential users, especially if there's no reason for it that is obvious to the user. (Then again, perhaps I'm being too optimistic about the security-conscientiousness of users.) If your extension currently uses the tabs API, then it already carries this notice anyway.

like image 138
apsillers Avatar answered Oct 07 '22 17:10

apsillers