Search code examples
javascriptgoogle-chromechromiummozilla

When using custom protocols or url scheme's, the window.open() method opens a blank page in Google Chrome


When I use window.open(url,'_blank') on a valid https url scheme, the browser opens a new tab with the URL.

For instance - execute the following in Chrome Browser console:

window.open('https://google.com','_blank')

This opens a tab or window (based on browser settings) and it opens google.com.

However if I use a custom protocol or URL scheme as follows:

window.open('tryme://helloworld/XXX/VGhpcyBpcyBhIHRlc3QgdXJs==','_blank')

Chrome Console Then a blank tab with "about:blank" is opened. This behavior seems to be happening only for chrome, Mozilla seems to work for both the URL scheme's.

Is there any ongoing issues with chrome or is this how it is supposed to work ?


Solution

  • I had to remove my previous answer suggesting you use a variable declaration when opening the link which will result in new window containing the url in the address bar but not actually accessing it.

    I would suggest that this is a security feature of Google Chrome refusing to access protocols other than http, https, ftp and file

    Unfortunately I was not able to find this in the official documention however you will find that using URL() to create a location you will get the expected result

    let newLocation = new URL('tryme://helloworld/XXX/VGhpcyBpcyBhIHRlc3QgdXJs==')
    

    returning

    {
      ...
      protocol: "tryme:"
      pathname: "//mytest.com"
      ...
    }
    

    However google chrome will refuse to update

    window.location = newLocation
    

    it would be nice if it would return an error message but doesn't do so. You will also find, that using the new URL() will work for supported protocols.

    Hope that helps. I will update this answer if I find definitive proof in an official documentation but I am pretty sure google high securitiy approach on chrome is the reason for this not being possible