Search code examples
browser-extensionbrave-browser

Chromium browser (Brave) default home page URL


I made a browser extension that overrides the new tab page for brave (it also works on chrome), and I want to add a button that opens the original page so that I can see the stats shown there. Is there an URL I could have this button go to?

If there isn't a URL, is there a way to get the values of the stats? (trackers blocked, bandwidth saved, time saved)


Solution

  • I'm an engineer at Brave, and appreciate the question!

    There is currently no API option to retrieve the New Tab Stats, though I will certainly follow through with filing that feedback for consideration.

    Unfortunately, there also does not appear to be a way to temporarily have Chromium ignore your custom New Tab Page, and instead open the browser's default New Tab Page. I was hoping there would be an extension API to temporarily unset the chrome_url_overrides, but that does not appear to be the case with Chromium.

    One approach you could take is to avoid an official override entirely, and instead listen for the opening of new tabs in the browser. If the user opens a new tab, redirect it to your own custom homepage. That way, you could set a flag to sometimes not redirect, and enable the user to view the browser's NTP.

    let override = true;
    const newTabURL = "chrome://newtab/";
    
    // Listen for all "new tab" events
    chrome.tabs.onCreated.addListener( ({ id, url, pendingUrl }) => {
    
        // We might have been instructed to ignore this event
        if ( !override ) {
            override = true;
            return;
        }
    
        // If the new tab is the default new tab page
        if ( newTabURL == ( url || pendingUrl ) ) {
            // Redirect this new tab to our internal page
            chrome.tabs.update( id, {
                url: chrome.runtime.getURL("index.html")
            });
        }
    
    });
    
    // In this example, clicking the browser action button
    // instructs the extension to allow the default NTP to
    // be displayed.
    chrome.action.onClicked.addListener( () => {
        override = false;
        chrome.tabs.create({ url: newTabURL });
    });
    

    Because this extension will be used outside of Brave, a way to detect Brave (for optional messaging and instructions), would be good too:

    const isBrave = navigator.userAgentData.brands.some(
        ({ brand }) => brand == "Brave"
    );
    

    I hope this helps!