简体   繁体   中英

Optional newtab override in Chrome extension

I want to make the newtab override in a Chrome Extension optional. A user should be able to see a dashboard on their newtab page, OR, if they don't want to, turn that off and use the standard Chrome one (or another extension).

However, I'm having problems with this.

Previously, we checked this setting on each time a new tab was opened using the chrome.tabs.onUpdated API. However, Google didn't like this without the chrome_url_overrides manifest permission and pulled the extension from the webstore.

After adding the chrome_url_overrides the setting which shows/hides the dashboard on newtab is broken and it shows the dashboard on 100% of new tabs.

Does anyone have a workaround for this?

you have to keep chrome_url_overrides in manifest and store the user choice (dashboard or default) in a localStorage or chrome.storage variable. Then you'll have to check that variable in your newpage javascript file. Something like this:

if (typeof localStorage.behaviour !== 'undefined' && localStorage.behaviour == 'default' )
    chrome.tabs.update({url:"chrome-search://local-ntp/local-ntp.html"})
else {
    //other stuff
}

if user choose to keep default page you'll have to give an alternative way to change his mind by adding another route to the dashboard. A good idea could be via extension popup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM