How to check in JavaScript if KM is being used?

I have a number of browser scripts (JavaScript) that I trigger from KM, but these same scripts may be used by others who do not have this luxury :slight_smile:

I want to conditionally run something depending on whether the script was triggered by KM.

For example, if it's run by someone without KM:


and for me:

results (which shows in KM window)

So I was thinking it would be something like this:

if (typeof document.kmvar.isKM === undefined) {
} else {

(Note that isKM is a variable that I set to "true").

Currently, I have to either comment out the browser alert()


… or I end up getting both:


What is the simplest/safest way of wrapping code so that it does not bug out for folks who are not using KM?