How can I refresh Chrome from within WebStorm? - google-chrome

While the WebStorm debugger is pretty robust, I prefer the Chrome console. I'm unable to make use of WebStorm's live reload feature, as it a function of the debugger and won't work while the Chrome console is open. Having to manually give Chrome focus every time I want to refresh is a headache, so does anyone know of easy way to trigger a refresh in Chrome without leaving WebStorm?

I happen to be on a Mac, so was able to work out a solution by utilizing WebStorm's External Tools configuration and AppleScript. Here are the steps:
Define an External Tool configuration in WebStorm
Open WebStorm preferences (⌘,)
Go to Tools --> External Tools
Create a new configuration:
Click the '+' button (a dialog will appear)
Set the name/description as preferred
Uncheck Open console
Set Program to osascript
Set Parameters to -e "tell application \"Google Chrome\"" -e "repeat with theWindow in (windows)" -e "repeat with theTab in (tabs of theWindow)" -e "if theTab's URL contains \"localhost\" then" -e "reload theTab" -e "end if" -e "end repeat" -e "end repeat" -e "end tell"
Press OK to save
At this point, you can go to Tools --> External Tools --> to refresh all chrome tabs whose URL contains "localhost".
You can also map a key combination in the Keymap section of preferences
For reference, here's the AppleScript being executed:
tell application "Google Chrome"
repeat with theWindow in (windows)
repeat with theTab in (tabs of theWindow)
if theTab's URL contains "localhost" then
reload theTab
end if
end repeat
end repeat
end tell
Update:
The external tool configuration and keybind is great, but left something to be desired. TypeScript takes time to compile, so after saving I was left spamming my refresh keybind until I saw my changes... What I really wanted is for Chrome waited for all of the TypeScript to compile before refreshing. This is what I came up with:
By setting the command of an npm run configuration to version, you can setup a run configuration that effectively does nothing but invoke external tools (see this post). I used this strategy to create a run configuration first invokes Compile TypeScript and then the Refresh Chrome Tabs script I defined earlier. The key here is that these external tools are run sequentially.
To take it a step further, I defined a macro that will "Save All" and then "Run" and rebound ⌘S to run invoke this macro. Now, whenever I save, Chrome is automatically refreshed after the TypeScript has been compiled, without any additional key presses.

Related

Run CloudEndPoints Explorer on Local HTTP

I'm trying to run the Api Explorer in LocalHost But it always show the Error
The API you are exploring is hosted over HTTP, which can cause problems.
So I follow the instruction
Go to File Explorer then paste this to address bar >> C:\Program Files (x86)\Google\Chrome\Application (or just go to where you can find your chrome.exe)
Right click chrome.exe > send to > Desktop (Create Shortcut)
Go to your desktop then find the chrome shortcut you've created.
Rename it to ChromeForTesting (this step is optional)
Right click the shortcut, then Click Properties
At the "Target", paste the following at the end of the link
--user-data-dir=test --unsafely-treat-insecure-origin-as-secure=http://localhost:8080
so Target should look somewhat similar to this
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=test --unsafely-treat-insecure-origin-as-secure=http://localhost:8080
Click Ok..
During testing close all of your opened google chrome browser.
Then double click ChromeForTesting shortcut (the one you've created), when a prompt appears, just click ok..
But After compelting this When I run that shortcut it will give the error
you are using unsupported command line flag --user-data-dir=test --unsafely-treat-insecure-origin-as-secure=http://localhost:8080
I also try to click load unsafe script but this is also not working.
Here is screen shot.

How to enable "Preserve Log" in Network tab in Chrome developer tools by default?

How to enable "Preserve Log" in Network tools in Chrome developer tools by default? Everytime I press F12 and then select Network tab, I need to click preserve log checkbox to make it preserve request/responses. Is it possible to have it checked all the time by default?
By the way this feature works in "Firefox Developer" edition. When I click "Persist Logs" and close and then open the browser & DEV tools window again, it is still checked.
UPDATE - 6th March 2019
This will be fixed in Chrome 73. But if you want to try it before that then install Chrome Canary. It's working there. To enable/disable this persistence just go to Dev tools settings and check/uncheck Preserve Log under network section as shown below.
Thanks to the team for fixing it. Better late than never.
I have a small solution to that problem. I don't know whether it works correctly.First, click three dots->More tools -> Developer Tools. In that, click the three dots button(the name will be Customize and Control Dev Tools. In that, click settings.You will see a list of options with a main heading Preferences. From that, browse down to Console option. In that, just tick the option 'Preserve log upon navigation'. I guess this will solve your problem.
Automate keystrokes to set chrome with persistent logs on Network tab. Tested with Chrome 66.
Make sure xdotool is installed
Launch chrome
Put the code below in a bash script chrome_auto.sh to send all the keys to: open a tab, dev tools, settings, set 'persistent logs', type the URL and hit enter.
#!/bin/bash
url="https://www.stackoverflow.com"
if [ -n "$1" ]; then
url="$1"
fi
# find chrome window id
wid=$(xdotool search --class Chromium | tail -n1)
# build tab key sequence to set 'persistent logs'
tabkeys=$(for i in {1..24}; do t+="Tab ";done ;echo "$t space")
# base xdotool command
cmd="xdotool windowactivate --sync $wid"
# make chrome dance :-p
$cmd key ctrl+t
$cmd key F12
sleep 1
# open settings, move to desired option and select it
$cmd key F1 $tabkeys
sleep 1
# move cursor to URL box and type URL
$cmd key F6 type "$url"
$cmd key Return
Use the script as
./chrome_auto.sh "https://stackoverflow.com/questions/45133659"
Also, chrome can be launched with dev tools open for every tab. If this is used, comment out the line with key F12
chromium --auto-open-devtools-for-tabs > /dev/null 2>&1 &

Failed to start native messaging host on Windows, "COMSPEC is not set"

I have a chrome extension that communicates with a native messaging host to get some data.
The issue is, when I launch the Chrome browser via the shortcut or via the pinned shortcut in the taskbar, the extension is not able to connect to the host. I always get the error:
Failed to start native messaging host.
However, if I launch the chrome.exe via command prompt, everything works fine.
Things I tried with no success:
The taskbar shortcut has no extra flags. The target field has the
following value: "C:\Program Files(x86)\Google\Chrome\Application\chrome.exe"
I tried with the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Google\Chrome\NativeMessagingHosts\com.company.extension
I tried with the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts\com.company.extension
I tried with the registry entry under
HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\com.company.extension
Tried launching the chrome.exe as administrator from the file explorer.
Update:
I added the flag --enable-logging --v=1 to the shortcut to enable logging and when I launch it I get the following output in the console:
[11036:4160:0302/113902.866:ERROR:native_process_launcher_win.cc(140)] COMSPEC is not set
[11036:11856:0302/113902.882:ERROR:native_process_launcher_win.cc(140)] COMSPEC is not set
Update
Upon investigating the chrome.exe process via Process Monitor, I found that there is no COMSPEC environment variable available to it when it is spawned via explorer.
Is there anything else that I can try or something that I am missing here?
As mentioned in the log, Chrome stumbles to start an external process, since COMSPEC, an environment variable pointing normally to cmd, is unset:
[11036:4160:0302/113902.866:ERROR:native_process_launcher_win.cc(140)] COMSPEC is not set
The behavior is different for launching Chrome from cmd itself, since it sets the variable for itself (ans spawned processes).
This can be confirmed by inspecting the Chrome process with Process Explorer.
One can run rundll32 sysdm.cpl,EditEnvironmentVariables as admin (e.g. from admin command line) to open the environment variable settings.
Alternatively, the dialog can be navigated to from Control Panel > System and Security > System > Advanced system settings > Advanced > Environment Variables...
ComSpec is usually set in System variables to
C:\WINDOWS\system32\cmd.exe
Adjust as necessary for your system install. For this setting to apply, you need to log out and log back in, or better yet restart the system.

debug mode for logging any commands in the sublime console

I used that command but forgot how to turn it on:
In sublime console, which is invoked by ctrl+` I typed something like ...
turn_on_debug_mode
... and sublime console started to log every command I run. For example, if I press right mouse button on the view and click Copy file path then in the sublime console I found logging of this action with the name of invoked command like copy_file_path.
So that was an easy way to grab names of commands that I could use in self-written sublime plugins.
The problem is that I do not remember how to turn that debug mode on.
In the console input:
sublime.log_commands(True)
To view keystrokes:
sublime.log_input(True)

Prompted by "Google Chrome didn't shut down correctly.... "

Using Google Chrome 38.0.2125.111 m in a Windows 7 environment. It is launched by a batch file & set to go to a specific (internal) URL. The Windows environment is going to be locked down, permitting only a handful of options available to the user.
Chrome is being used because IE will be accessing a different site. Without going into boring detail, using both sites on a single browser allowed a user to access an account that wasn't theirs. Both browsers will be launched using one of two batch files. The Chrome batch file supplies the username & password to bypass a login screen on that application.
To keep from opening multiple windows in Chrome, the following batch file is used:
taskkill /f /t /im chrome.exe > NUL
ping -n 3 127.0.0.1 > NUL
START /max chrome "http://myinternalwebsite?uid=x&pwd=y"
Taskkill is used to close chrome (/f = force /t = terminates process & any child ones /im = image name).
If the Chrome session is closed (using the X at the upper right corner of the screen), the batch file works fine. However, if there is already a chrome instance running, we get the yellow bar with the frowning folder & a message saying:
Google Chrome didn't shut down correctly. To reopen the pages you had
open, click Restore.
I have tried several command line options when launching Google Chrome, but none will keep the message from displaying. Ones I have tried are:
--disable-restore-session-state
--disable-session-crashed-bubble
--incognito
among others. I've experimented with some of the settings in Chrome, but none have (yet) worked. The --incognito option works - sort of. It keeps blocking plugins, one of which is Silverlight - one of the chief components for the website to function. Even though it does get rid of the message, it leaves the site not functioning properly.
The intent on using Taskkill to flush any existing Chrome sessions was to prevent the user opening up a dozen different Chrome instances of the same thing.
Is there any way to keep a user from opening multiple instances of Chrome that won't leave Chrome thinking it didn't close properly? Given the user restrictions, I'm not sure that a script/batch file to edit the Preferences file in the Chrome folder will work. An extension may be an option, but a third party application will not be.
Would appreciate any thoughts or assistance.
Thanks!
Chromium writes exit status into Preferences file. When it starts it writes Preferences file with:
"exited_cleanly": false
and upon clean exit writes Preferences file with:
"exited_cleanly": true
To prevent message about unclean shut down make sure that you have "exited_cleanly": true written in your Preferences file
On my Linux kiosk running on Raspberry Pi this sed command line added to /etc/rc.local fixes issue permanently:
sed -i 's/exited_cleanly\":\ false/exited_cleanly\":\ true/g' /home/pi/.config/chromium/Default/Preferences