3

I would like to create a launcher launching:

chromium-browser chrome://inspect

However, this simply opens the chromium as if not url has been specified at all.

Is it even to start Chromium opening a chrome:// url?

1 Answer 1

3

While "normal" url's do work as expected, it seems impossible at first to use the chrome:// urls from a command, and there is nothing in the man chromium-browser man page on this.

However, it is very well possible to work around this, with the help of xdotool.

How it works

  • install xdotool

    sudo apt-get install xdotool
    
  • Use the following command in your .desktop file:

    /bin/bash -c "chromium-browser&sleep 2&&xdotool type 'chrome://inspect'&&xdotool key Return"
    

What it will do is open chromium browser, xdotool will type the chrome://inspect url and (simulate) press return.

Effectively this will do exactly what you want.
No need to say that you can replace chrome://inspect with any other of the chrome:// commands.

Note

In the command, there is a small break included of 2 seconds, to make sure the browser is loaded before xdotool starts to type. On my system (not the most recent) it can be changed to sleep 1 and still work perfectly. You can experiment a bit with it.


edit

Alternative

Dirty or not, a solution should always work. I tried the solution above now and then, and found that occasionally, it takes too long for the chromium-browser window to appear. Especially when the computer is heavily occupied, there is a chance xdotool starts typing "blindly".

The solution below is "time-proof" and should work under all circumstances; it makes sure xdotool only starts typing when a new chromium-browser window appears within appr. 15 seconds.

How to use

  • Copy the script below into an empty file
  • Save it as run_chrcommand.py
  • use as command in your .desktop file:

    python3 /path/to/run_chrcommand.py
    

The script

#!/usr/bin/env python3
import subprocess
import getpass
import time

user = getpass.getuser()
get = lambda x: subprocess.check_output(["/bin/bash", "-c", x]).decode("utf-8")
ws1 = get("wmctrl -lp"); t = 0
subprocess.call(["/bin/bash", "-c", "chromium-browser&"])
while t < 30:      
    ws2 = [w.split()[2] for w in get("wmctrl -lp").splitlines() if not w in ws1]
    procs = [[p for p in get("ps -u "+user).splitlines() \
              if "chromium-bro" in p and w in p] for w in ws2]
    if len(procs) > 0:
        command = "xdotool type 'chrome://inspect'&&xdotool key Return"
        subprocess.call(["/bin/bash", "-c", command])
        break
    time.sleep(0.5)
    t = t+1
3
  • That's a really ugly hack... but it works! Thanks Jan 24, 2015 at 15:32
  • @RemcoHaszing always looking for the clean solution. But if there isn't, tools like xdotool are great :) Jan 24, 2015 at 15:36
  • @RemcoHaszing Hi Remco, found out that occasionally the window appears too late for xdotool. The edit always works. If you need more then one chromium command, let me know, then the command should be made an argument. Jan 24, 2015 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .