Sublime Forum

Open in Browser does not work with Sublime Text set as default program to open .html files

#1

I’m using the latest version, Sublime Text 3.2, on Windows 7 Professional. When I right-click on a .html file, an option “Open in Browser” shows in the pop-up menu. As long as I set my .html files to open in a browser such as Firefox as my default program, the “Open in Browser” option will open in that browser. If I set my .html files to open in Sublime Text as my default program which I prefer, the “Open in Browser” option does not do anything. I have the View in Browser package installed which solves the problem though is there any way to configure Sublime Text 3.2 to get the “Open in Browser” option to open .html files in the default browser? It is not a big deal, guess annoying more than anything that this option exists and does not do anything with Sublime Text set as the default program to open .html files.

Thanks!

Greg

0 Likes

#2

You can always override the command yourself. (maybe a package already exists?) The original can be seen by running the command View Package File and opening the file Default/open_in_browser.py. It uses the python package webbrowser which may have issues itself.

1 Like

#3

Thanks for your help in getting me on the right path! :grinning: After futzing with this since yesterday afternoon I was able to get the “Open in Browser” option to finally work by creating a new folder named “Default” in this path C:\Users\username\AppData\Roaming\Sublime Text 3\Packages\Default and saving a copy of open_in_browser.py in that folder to override the original open_in_browser.py file. All I had to do was register firefox and use the get function to return a controller object for firefox by adding the code in bold below. This can be changed to a different browser such as Chrome by giving the path to the Chrome executable and switching ‘firefox’ to ‘chrome’.

if self.view.file_name():
ffpath = 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe’
webbrowser.register(‘firefox’, None, webbrowser.BackgroundBrowser(ffpath), 1)
webbrowser.get(‘firefox’).open_new_tab(“file://” + self.view.file_name())

0 Likes