Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solved] How to use a custom file:/// .html page as new tabs on Firefox #980

Closed
Delgan opened this issue Jul 22, 2023 · 8 comments
Closed

Comments

@Delgan
Copy link

Delgan commented Jul 22, 2023

What command or commands

Hi. I use Vimium C a lot and I wanted to thank you for all the work you do!

A recurring problem, though, is the inability to use Vimium on "about:home" and "about:newtab". I know you developed "NewTab Adapter" as a workaround. However, I'd like to know your opinion on the possibility of using a customized .html page.

My goal is to have an aesthetically pleasing page that lets me open a bookmark with just one keypress, like this (example using sadparadiseinhell/null):
Screenshot 2023-07-22 at 10-57-49 null

As far as I know, it's not possible to do something like this as of today (without running a local server).

How should a feature do

I would like Vimium C to provide an option to override home page and new tab using custom HTML.

As an example, I think this extensions provides a way to use local page: https://github.com/cadeyrn/newtaboverride

Let me know your opinion of this and if you would accept a PR.

Browser and OS

  • Browser name: Firefox 115.0.2
  • OS name: Linux 6.4.4-arch1-1
@gdh1995
Copy link
Owner

gdh1995 commented Jul 23, 2023

The biggest problem is Firefox doesn't allow web extensions to open a tab of a file://* URL.

I'm not sure what https://github.com/cadeyrn/newtaboverride does. However, if it dynamically replaces the HTML code of its newtab page with your configured HTML code, then there're some JS/CSS permission issues to solve.

Although it's possible to solve the permission issues, I think the way to solve them will affect what NewTab Adapter should be.

Here's an idea which is not verified yet:

@Delgan
Copy link
Author

Delgan commented Jul 23, 2023

@gdh1995 Thanks for answering.

I'm not sure what https://github.com/cadeyrn/newtaboverride does. However, if it dynamically replaces the HTML code of its newtab page with your configured HTML code, then there're some JS/CSS permission issues to solve.

As you have guessed, the extension saves the provided file in localStorage and later re-inserts it in a template page using insertAdjacentHTML().

It works fine for CSS (as long as <style> and not <link> is used), but indeed this doesn't work for Javascript.

I could indeed create another extension, however:

  • It would mainly be a copy/paste of NewTab Adapter with an added feature, so I'd rather contribute to NewTab Adapter directly (assuming it doesn't add too much maintenance burden). But if you think this is out-of-scope, I can understand.
  • This doesn't solve the very annoying problem of "not focused content" when a new tab is created (#1411465). I know NewTab Adapter implemented a workaround which consists of closing the new tab created by the browser, and immediately re-opened it with focused content, unfortunately it causes very disturbing visual flickering. However, using Vimium C to open a new tab elegantly solves the problem, hence my proposal.

To integrate such feature to Vimium C, we could imagine a custom <div> in pages/blank.html. Then in the configuration page of Vimium C, we could add a <textarea> for "Custom HTML", and let users paste whatever they like. Static HTML/CSS is enough to create beautiful start pages.

It looks to me that such solution have great potential to improve usability without adding much complexity. I'm not familiar with the code base, though, and I would respect your decision if you think this is not good fit for Vimium C.

Again, if you'd like me to open a PR just to see, it would be a pleasure to contribute.

@gdh1995
Copy link
Owner

gdh1995 commented Jan 7, 2024

The main advantage of this solution compared to using another extension is that it maintains the browser's focus on page content. This avoids the need for cumbersome workarounds such as closing and reopening the new tab to remove focus from the address bar, which creates visual disturbances.

Sorry I missed this problem. A much easier way is just to forget your browser's Ctrl+T shortcut, and use Vimium C's createTab command to do so:
image
image

@Delgan
Copy link
Author

Delgan commented Jan 7, 2024

@gdh1995 Thanks for the suggestion.

Actually, I'm already using the built-in t shortcut which keeps focus on content. The problem is that I can't configure "New Tab URL" to open a link that starts with file://, since Firefox disallows it (from what I understood). That's why I tried to build a workaround injecting HTML in pages/blank.html.

@gdh1995
Copy link
Owner

gdh1995 commented Jan 8, 2024

Yes, opening file:// is limited by Firefox.

You may run a small static-resource HTTP server using python -m http.server or Nginx - a 2-process nginx is very cheap and only takes up 3MB system memory.

@Delgan
Copy link
Author

Delgan commented Jan 12, 2024

You may run a small static-resource HTTP server using python -m http.server or Nginx - a 2-process nginx is very cheap and only takes up 3MB system memory.

That is what I was trying to avoid. It'll work, that's for sure, but the thought of setting up a local server just to personalize Firefox's new tab makes me cringe inwardly...

However, I figured out it was possible to use a local HTML page through AutoConfig on Firefox. It's not well documented, and is subject to breakage from version to version, but at least it lets you run JavaScript and even focus on content automatically.

For reference, here is the autoconfig.js I'm using:

pref("general.config.filename", "firefox.cfg");
pref("general.config.obscure_value", 0);
pref("general.config.sandbox_enabled", false);

And here is the firefox.cfg:

//
var Services = globalThis.Services;
var {classes:Cc,interfaces:Ci,utils:Cu} = Components;

try {
 Cu.import("resource:///modules/AboutNewTab.jsm");
 AboutNewTab.newTabURL = "file:///home/delgan/home.html";

  Cu.import("resource:///modules/BrowserWindowTracker.jsm");
  const Services = globalThis.Services; 
  Services.obs.addObserver((event) => {
    window = BrowserWindowTracker.getTopWindow();
    window.gBrowser.selectedBrowser.focus();
  }, "browser-open-newtab-start");
} catch(e) { Cu.reportError(e); }

Closing the ticket as resolved, thanks for your time. 👍

@Delgan Delgan closed this as completed Jan 12, 2024
@gdh1995 gdh1995 changed the title Ability to use a custom .html page for new tabs Ability to use a custom file:/// .html page as new tabs on Firefox Jan 15, 2024
@gdh1995 gdh1995 pinned this issue Jan 15, 2024
@gdh1995
Copy link
Owner

gdh1995 commented Jan 15, 2024

Hello, there's another way by modifying properties on about:config:

See fastaddons/GroupSpeedDial#36 (comment), which was referred to in #1021 (comment) .

capability.policy.policynames = "localfilelinks"
capability.policy.localfilelinks.checkloaduri.enabled = "allAccess"
capability.policy.localfilelinks.sites = "moz-extension://UNIQUE_ID_OF_MY_ADDON_ON_YOUR_PC"

@Delgan
Copy link
Author

Delgan commented Jan 20, 2024

@gdh1995 I can confirm that it works very well! Thank you very much for sharing the tip.

To summarize:

  • I use built-in Firefox settings to redirect "Home Page" to a local file.
  • I use firefox.cfg to redirect "Firefox New Tab" (Ctrl+t) to a local file.
  • I use about:config / autoconfig.js to redirect "Vimium New Tab" (t) to a local file.

It's embarrassingly convoluted, but at least I got the result I wanted, thanks!

@gdh1995 gdh1995 changed the title Ability to use a custom file:/// .html page as new tabs on Firefox [Solved] How to use a custom file:/// .html page as new tabs on Firefox Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants