1

I would like to write an WebExtension to have a blank private browsing page, inspired by an old extension: https://github.com/iPotable/BlankPrivateBrowsingPage

I thought I could use chrome_url_overrides for any chrome page. So I tried:

{
  "manifest_version": 2,
  "name": "Blank private browsing page",
    "chrome_url_overrides" : {
       "chrome://browser/content/aboutPrivateBrowsing.xhtml": "index.html"
  },
  "version": "0.1"
}

But it seems that it can be used only for certain chrome pages, right?

See: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/chrome_url_overrides

A second option that I tried was a UserScript:

// ==UserScript==
// @name Blank aboutPrivateBrowsing page
// @include chrome://browser/content/aboutPrivateBrowsing.xhtml
// ==/UserScript==

window.location.href="about:blank";

But seems that Greasemonkey can not handle chrome URLs.

Can anyone think of another solution?

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Wuff
  • 257
  • 1
  • 8
  • 1
    Take a look at this doc: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/windows/create option names incognito. – Mark Davydov Nov 28 '17 at 09:48

1 Answers1

0

Currently, you cannot override about:newtab in private mode. However, what you should be able to do inside a WebExtension:

Then you will have more or less the same.

Code:

function handleUpdated(tabId, changeInfo, tabInfo) {
    if(changeInfo.favIconUrl){
        //console.log("favIconUrl updated is " + changeInfo.favIconUrl);

        if (tabInfo.incognito && changeInfo.favIconUrl.indexOf("privatebrowsing") > -1){
            //console.log("opening about:blank..");
            browser.tabs.update({url: "about:blank"});
        }
    }
}

browser.tabs.onUpdated.addListener(handleUpdated);

The code above sadly gives a noticable graphical glitch. Instead of favIconUrl you can probably use tab.title == "New Tab" as well (but that will only work for English versions of Firefox).

Smile4ever
  • 3,491
  • 2
  • 26
  • 34
  • Thank you for your quick answer. But I am still not sure in which format I refer to the chrome://browser/content/aboutPrivateBrowsing.xhtml? ` browser.webRequest.onBeforeRequest.addListener( listener, {urls: ["chrome://browser/content/aboutPrivateBrowsing.xhtml"]} ); ` Doesn't seem to work. – Wuff Nov 28 '17 at 15:16
  • I just checked following example: https://github.com/mdn/webextensions-examples/tree/master/http-response ... But surprisingly it doesn't change the content. So I am confused how to get webRequest.onBeforeRequest working!? – Wuff Nov 28 '17 at 15:20
  • I would have liked to done this browser.webRequest.onBeforeRequest.addListener( listener, {urls: ["about:privatebrowsing"]} ); but it is not possible, see https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Match_patterns – Smile4ever Nov 28 '17 at 19:03
  • Thank you for your answer, but detecting that the about:privatebrowsing page seems not so easy. console.log(tab.url) returns about:blank on about:privatebrowsing... Here my first try: https://github.com/bbo2adwuff/BlankPrivateBrowsingPage/blob/master/src/background.js, but because of the about:blank. Even if I use tabs.create with an index.html then it keeps on opening tabs indefinitely. Does every new tab starts with about:blank??? – Wuff Nov 30 '17 at 15:52
  • It seems that every new tab starts out as about:blank when it first gets created. I have updated the code above. – Smile4ever Dec 01 '17 at 15:49
  • Perfect! Thanks! I tried on onUpdated before as well. But didn't succeed. Nice idea of using the facIcon ;) – Wuff Dec 04 '17 at 07:55