brookhong / Surfingkeys

Map your keys for web surfing, expand your browser with javascript and keyboard.
https://chrome.google.com/webstore/detail/surfingkeys/gfbliohnnapiefjpjlpjnehglfpaknnc
MIT License
5.4k stars 482 forks source link

How to open about:newtab instead of about:blank in firefox? #1005

Open fatjing opened 5 years ago

fatjing commented 5 years ago

Error details

SurfingKeys: 0.9.45

Browser: firefox 68.0.1 / windows 10

Context

mapkey('on', '#3Open newtab', function() {
  tabOpenLink("about:newtab");
});

doesn't work

Dima-369 commented 3 years ago

I am also interested because this works in Vimium in their createTab function.

This is quite useful because with the Dark Reader extension the about:newtab page is dark instead of white.

Dima-369 commented 3 years ago

This is quite useful because with the Dark Reader extension the about:newtab page is dark instead of white.

https://superuser.com/a/1400442 specifies to edit browser.display.background_color in about:config to a dark color which does the job for the about:blank page, so that helps.

But apparently, on hitting on, in the tab Firefox's location bar is not initially highlighted as it would be when one hits cmd+t (in macOS).

I glanced over the code in vimium and in main.js they are using this code and even mention the issue with about:newtab but I have had no luck patching this into SurfingKeys :(

// Firefox does not support "about:newtab" in chrome.tabs.create.
if (winConfig["url"] === Settings.defaults.newTabUrl)
  delete winConfig["url"];
return chrome.windows.create(winConfig, callback);

I tested this in Chrome and there the key sequence on works just as one would expect: It opens a new tab and focuses the location bar.

Dima-369 commented 3 years ago

The code below works but one has to recompile the extension. It redirects about:blank to about:newtab:

function openUrlInNewTab(currentTab, url, message) {
        var newTabPosition;
        if (currentTab) {
            switch (conf.newTabPosition) {
                case 'left':
                    newTabPosition = currentTab.index;
                    break;
                case 'right':
                    newTabPosition = currentTab.index + 1;
                    break;
                case 'first':
                    newTabPosition = 0;
                    break;
                case 'last':
                    break;
                default:
                    newTabPosition = currentTab.index + 1 + chromelikeNewTabPosition;
                    chromelikeNewTabPosition++;
                    break;
            }
        }

      let tabConfig = {
            url: url,
            active: message.tab.active,
            index: newTabPosition,
            pinned: message.tab.pinned,
            openerTabId: currentTab.id
      };

      if (url === "about:blank") {
        delete tabConfig["url"];
      }

      chrome.tabs.create(tabConfig, function(tab) {
        if (message.scrollLeft || message.scrollTop) {
          tabMessages[tab.id] = {
            scrollLeft: message.scrollLeft,
            scrollTop: message.scrollTop
          };
        }
      });
    }