Is It Possible to Detect if Chrome Dev Tools Window Is Showing?

I want to open DevTools (Console) in Google Chrome but only if it is not already open. The window may already be open and be docked or floating. Is there a way to detect if the console is open and whether it is docked or not?

The aim is to do this:

  • Run a Chrome JavaScript
  • Open the console to show results (by sending keystroke CMD + Alt + J), but only if the console is not already open.

Hey Lloyd,

If the window is floating then Keyboard Maestro can detect it by name.

If not then there's no direct method I can see, but a little JavaScript will let you infer whether the dev-tools panel is open

window.outerHeight - window.innerHeight

This is also affected by things like the Keyboard Maestro Forum editor though, so you may want to Google for some more solid elements to look for/at with JavaScript.

And if you have the panel on the side of the window instead of in-line vertically you'll have to work with width instead of height.

-Chris

Ah, that is a good plan. I thought that the floating window could be detected, but not when docked (and I normally have it docked). So a JS solution looks to be the way forward. I did wonder whether one of the dev tools controls might be detected as a button in order to ascertain whether the panel is showing. Thanks :slight_smile:

I looked to see if that could be done with AppleScript UI-Scripting, and it can't – so I don't think Keyboard Maestro's button-detector will work either.

It may be possible to detect elements in the dev-tools panel with JavaScript, but I wouldn't bet on it. The only references I found to that are old and don't work anymore.

-Chris

Have you considered using the KM action for running javascript then showing results in a window (or saving to a variable for further use)?

If that doesn’t work - i have run into situations where I can trigger a javascript in chrome via AppleScript, and that works just as successfully as if I was typing the JS in the chrome devtools. I could be wrong though, maybe that’s not a solution for all situations.

If you still need the Chrome inspector, (forgive me if this is too obvious), you’ve considered using a “found screen” image condition to look for a part of the inspector to be open?

Hi Joel - That's a good point - I certainly could do that. However, the script I am running will be used by other people in a number of browsers/OSs, so the results have to output to the console. As such I do need to verify what others will see, hence wanting to have KM automatically open it after running. But if the results are the same in a KM window as console, then I guess I'm fine to do that :slight_smile:

Also, 'found screen' is not too obvious—this is not something I have used before, but I'm glad you mentioned it because the ability to find something based on an image and click it will be VERY useful for another task :slight_smile:

The found image tools in KM are a huge help, but since apps and websites update their styling all the time (and even MacOS updates can change the appearance of things and break my macros), I try to find other solutions before relying heavily on the "found image". But for when we have no other choice, it's one of the most powerful features of KM.

I found a way to open Chrome JS Console that works for me consistently.

As you probably found out, the menu item or keyboard shortcut seem to work as a toggle, so you don't know if it's already open or closed.

However, if your project can allow you open a fresh tab right before toggling that shortcut, then I think you can always assume the Javascript Console is initially closed when you open a new tab.

In case it helps, here is a submacro that you can use in your other macros.

You can use it by passing the url of the page where you want to open the JS Console. For example:

It's simple, but every day there is someone new learning KM that might stumble across these posts and might find something new!

_TEMP-TESTING Macros.kmmacros (4.4 KB)

Cheers,

Joel