0

I am trying to create a "launch" page that is just a simple HTML page with a link of my bookmarks that I can edit myself. I want this page to come up when I open a new tab in Google Chrome. (In other words, I'm trying to create a custom HTML page that would automatically load in new Chrome tabs.)

I am using "New Tab Redirect" extension in Google Chrome to load this file when I open a new tab. The challenge is using a file:// URLs that would work on both Macs and PCs.

I have two laptops, one is Mac and the other is PC.

file:///tmp/bookmarks.html works on macos when I put my bookmarks in /tmp/bookmarks.html, but it doesn't work on PC. (I tried creating 'c:\tmp\bookmarks.html` on the PC but Chrome doesn't pick it up.)

file://C:/tmp/bookmarks.html works on PC but doesn't work on macos (I tried creating /C:/ and linking from tmp in there to /tmp but no dice).

Is there any file:// URL that would work on both systems?

P.S. Earlier, I tried using an http:// URL (running a local web server to share the bookmarks.html) but it was noticeably slow to load compared to loading a file:// resource

3
  • For windows, if you set the tmp in tmp/bookmarks.html as a share, then file://///localhost/tmp/bookmarks.html should work. Not sure about the mac side of the equation.
    – Yorik
    May 12, 2021 at 17:42
  • By "not sure" I meant I don't know exactly how to implement it, but I do expect e.g. setting up a SMB share in the same manner should work. Using "localhost" should resolve the same way to the same path on both machines. It may also be possible to not prepend the file protocol, but that depends on chrome. Not that you aren't actually grabbing from the network, just exposing the directory tree to the network interface.
    – Yorik
    May 12, 2021 at 20:22
  • Understood, thank you, @Yorik May 13, 2021 at 15:37

1 Answer 1

2

Edit: I misunderstood the question. OP can use the chrome-extension:// URL approach.

According to the wiki, your install paths are here:

Windows: C:\Users\**username**\AppData\Local\Google\Chrome\User Data\Default\Extensions\icpgjfneehieebagbmdbhnlpiopdcmna\

Mac: Macintosh HD\Users\**username**\Library\Application Support\Google\Chrome\Default\Extensions\icpgjfneehieebagbmdbhnlpiopdcmna\

You can place the file there for it to appear in both places.

chrome-extension://icpgjfneehieebagbmdbhnlpiopdcmna/

Just to drive the point home, C:\Users\Username\AppData\Local\Google\Chrome\User Data\Default\Extensions\icpgjfneehieebagbmdbhnlpiopdcmna\custom-html.html can be reached at chrome-extension://icpjfneehieebagbmdbhnlpiopdcmna/custom-html.html


old answer: As I understand it, you're trying to create the anchor in your custom HTML document?

You could write the document for Mac and then have a script rewrite the prefix:

// check if we are using Windows -- https://stackoverflow.com/questions/9514179/how-to-find-the-operating-system-version-using-javascript

if (window.navigator.userAgent.indexOf("Windows") != -1){

  // loop over all the anchors
  Array.from(document.getElementsByTagName("a")).forEach((a) => {

    // if it starts with file
    if (a.href.indexOf("file:///" == 0)) { 
      
      // do the actual replace (adjust as needed)
      a.href = a.href.replace("file:///", "file://C:/"); 
    }
  });
}
9
  • I am trying to create a custom HTML document that will load when I open a new tab in Google Chrome. May 12, 2021 at 16:15
  • The file URL should link to this document or is it inside the document?
    – cschl
    May 12, 2021 at 16:18
  • The file URL should link to this document. That's how Chrome knows where to find the document. May 12, 2021 at 17:00
  • I realize this is late, but: the github documentation shows where the plugin installs to. Can you use the chrome-extension:// approach? I set my redirect page to chrome-extension://<random>/options.html and it took me to that page. Maybe you already figured that out!
    – cschl
    May 12, 2021 at 22:47
  • 1
    I ended up using Vimium's "New tab URL" setting with the value of file:///C%3A/tmp/bookmarks.html to override the Chrome new tab value. May 17, 2021 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.