1
votes

I'm trying to do something like this in my webextension inside background script for firefox 52 browser :

Components.utils.import("resource:///modules/NewTabURL.jsm");
NewTabURL.override(value);

But firefox says that Components.utils - undefined . My extension based on chrome , so i need to use web extension addon type (. Is it possible to override newtab page in other way before Firefox 54 realize ?

Update : here is my little code which helps me did newtab replace , but it buggy (

var newTabUrl = browser.extension.getURL("../index.html");

    function handleActivated(activeInfo) {
        console.log("Tab ", activeInfo);
        if (activeInfo.url === "about:newtab") {
            browser.tabs.update(activeInfo.id, {
                url: newTabUrl
            });
        }
    }

    var querying = browser.tabs.query({
        currentWindow: true,
        active: true
    });

    const newtabdemo = {
        getActiveTab: function() {
            return browser.tabs.query({
                active: true,
                currentWindow: true
            });
        },

        openNewTabPage: function() {
            newtabdemo.getActiveTab().then((tab) => {
                var gettingInfo = browser.tabs.get(tab[0].id);
                gettingInfo.then(handleActivated);

            });
        }
    };

    browser.tabs.onCreated.addListener(newtabdemo.openNewTabPage);
1
Components.utils (e.g. Components.utils.import) is not part of WebExtensions. Remove it, and forget about it. Don't try to use anything connected to it. - Makyen

1 Answers

1
votes

You can create chrome override page for the newtab page.

Example:

"chrome_url_overrides" : {
  "newtab": "my-new-tab.html"
}