Override the Chrome new tab page with a webpage?

Viewed 7069

Is there a clean way for a Google Chrome extension to set a non-local webpage as the new tab page while also keeping the omnibox cleared or highlighted?

The chrome_url_overrides.newtab option in the extension manifest only allows local HTML pages.

Right now, I see two options:

  1. iframe the webpage in the local extension page. However, many websites won't work properly when iframed.
  2. Redirect the local new tab page to the webpage. However, this does not reliably highlight the omnibox, so users have to manually set focus to the omnibox before typing, which is a poor user experience.

The ideal solution would keep the webpage be the top frame of the new tab page, and the omnibox would be either cleared or highlighted.

Additional info:

  • There's an ongoing, unsolved thread on this topic here for the Chrome extension New Tab Redirect.
  • Using chrome.tabs.update to redirect the new tab page has historically highlighted the URL. However, this appears to be undocumented and unreliable. The highlighting broke in Chrome 34 and appears to be broken now in Chrome 61 (a bug I just reported).
1 Answers

Right now, this isn't quite possible. I've opened a feature request for Chrome extensions to better support this use case.

The two options in the meantime are:

  1. On the local extension new tab page, create an iframe to the webpage.

  2. In an extension background script, listen for new tab creation and update the URL to a website. This looks something like:

    // background.js
    
    // Listen for new tabs.
    chrome.tabs.onCreated.addListener(function (tab) {
    
      // Only redirect if this is a blank new tab (not opened by clicking a link).
      if (tab.url === 'chrome://newtab/') {
    
        // Show your website. This might highlight the omnibox,
        // but it's not guaranteed.
        chrome.tabs.update(tab.id, {url:'https://example.com'});
      }
    });
    

    As noted in the question, this has unreliably highlighted the URL in the past. The URL highlighting is broken as of now (Chrome stable v61) but should be fixed in v62.

Related