Sublime Forum

How to add Google Chrome as a browser to Sublime Text 3?

#1

I want to be able to use both Firefox and Google Chrome browers from Sublime

Problem: How do I open a html file in Google Chrome from Sublime Text 3?

I’m using:

  1. Ubuntu Linux Version 14.04
  2. Google Chrome Version Version 50.0.2661.75 (64-bit)
  3. Sublime Text 3 (build 3103) (Single User Licence)

I followed these instructions and created a sublime-build like this


{
** “cmd”: [“open”, “-a”, “Google Chrome”, “$file”]**
}

called “chrome.sublime-build”

I saved the build file, closed Sublime Text and restarted it. I tried to get Chrome to
open from Sublime Text by using Control + Alt + V.
I get Firefox opening up instead of Chrome.

I also tried

{
** “cmd”: [“open, “-a”, “/etc/alternatives/google-chrome”, “$file”]**
}

that also failed to work.

I tried an alternative approach.

I have control package manager installed , I followed instructions from this link

https://packagecontrol.io/installation

I type Control + Shift + P, then “Package Control”,

I do have options appear such as :
Package Control:Add Channel
Package Control: Add Repository
etc

but according to this link :

http://www.granneman.com/webdev/editors/sublime-text/set-up-sublime-text-to-preview-your-code-in-a-web-browser/

There should be a plugin called “View in Browser Plugin”, under the section “Method 1: Install the View in Browser Plugin”.

This option is not available

How can I add Google Chrome, so that I can open the html file from either Firefox or Chrome? I
don’t have much experience with this. Thanks in advance

0 Likes

#2

View in Browser is available from Package Control. ( the web site)
To create a build file, you need to know the full and exact path of your browser executable. Just typing the name of the browser won’t work.

You install View in Browser through Package Control in Sublime Text. Then select Install Package, type view, View in Browser should come up, then just select it.

Remember to restart ST after the package installs. View in Browser should work, but if not, you may have to tweak the settings. See the instructions at the Package Control web site.

0 Likes

#3

Many thanks Jackeroo.
I discovered that View in Browser Plugin had already been installed, I chose the Package Control ‘List Packages’ and ‘View in Browser’ was one of the listed packages.

I changed the build file to:
“cmd”: [“open, “-a”, “/etc/alternatives/google-chrome”, “$file”]

I used the built in mapping Control + Alt + C - to launch Chrome.

That is one problem solved, the next one is to find out what CRoss Origin Requests are and solve that (that I will have to do on a different forum).

Thank you for your help, my initial problem has now been solved.d

0 Likes

#4

auchomage, how do you change the build file? new to sublime and it defaults to mozilla for me. i was able to follow along until that last step where you stated that you changed the build file. plz halp!

0 Likes

#5

No need to edit build files. From the main menu select Preferences > Package Setting > View in Browser > Settings - User and insert

{
    "browser": "chrome"
}
1 Like

#6

i was not able to get this to work. it wouldn’t let me save the changes, saying that there were unexpected characters. i copy and pasted exactly what you have posted. :confused:

0 Likes

#7

Does the file consists of more content? It should be valid JSON and "browser": "chrome" should be a valid key-value pair inside it.

0 Likes

#8

As it is in the case of Firefox Developer Edition Browser…?

0 Likes

#9

I discovered that a quick fix, in order to open your code on Chrome and use its developer tools, is to right-click inside sublime text and choose “Copy File Path”. Then paste this path on Chrome’s address line and bingo!!

0 Likes

#10

Great! Thanks!

0 Likes

#13

I have been having these same issues and seeing people all over running into the problem too… the “Copy File Path” works but sort of defeats the purpose of having an “Open in Browser” shortcut.

After weeks of trying a million different things I FINALLY figured out what the issue is:

You DO want to install the “View In Browser” package, BUT there is a limit to how far the path will allow this to work… too long and it will default to IE or just open a folder a few folders back in Chrome. If you are sure to save your folders only 3-4 (Not sure the exact limit) directories away from C:, then it will work perfect.

I had mine in C:\Documents\Programming\HTML\MyCodes\LandingPage\index.html and it would open in IE and selecting “View in Browser” just opened the file explorer up to C:…\HTML. After I moved the ‘LandingPage’ folder to C:\Documents\LandingPage it will now Open in Browser to Chrome and View in Browser to Chrome. In fact you may not even need to install View In Chrome, “Open In Browser” might use deault browser set as long as the path to the HTML page is not too long, I will do additional testing.

0 Likes