Do you have your IDE and your browser open side-by-side? Do you want explicit control of when your browser refreshes with a single shortcut key? Auto-reloaders are cool but sometimes you need to preserve your browser-state whilst debugging. Opensource to the rescue!:
Windows
AutoHotkey makes this easy. I’ve assigned my F2 key to refresh my currently open tab in Chrome (irrespective of whether or not I am currently working in Chrome), using this script. I've adapted this script from elsewhere but have yet to find the source.
F2:: | |
; Save current window | |
WinActivate,ahk_class Chrome_WidgetWin_1 | |
; --------------------------------------- | |
; Refresh Chrome | |
Process, Exist, chrome.exe | |
If(ErrorLevel) { | |
WinActivate, ahk_pid %ErrorLevel% | |
Send {F5} | |
} | |
; --------------------------------------- | |
; Return to original window | |
WinActivate ahk_id %original% | |
return |
Mac
HammerSpoon is really powerful (just make sure to give it accessibility permissions, eg.). The LUA below script identifies the currently frontmost app and notes it down. It then changes focus to Chrome (opening Chrome if it’s not open; you can change browsers by changing ‘Google Chrome’ ), waits a second for this to happen, and refreshes the browser. It then changes focus back to your IDE.
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "r", function() | |
local current_focus = hs.application.frontmostApplication(); | |
hs.application.launchOrFocus('Google Chrome'); | |
local browser = hs.appfinder.appFromName('Google Chrome') | |
hs.timer.doAfter(.5, function() | |
hs.eventtap.keyStroke({"cmd"}, "r", 1000, browser); | |
local current_focus_name = current_focus:name(); | |
hs.timer.doAfter(.5, function() | |
hs.application.launchOrFocus(current_focus_name); | |
end) | |
end | |
) | |
end) |