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:

alert(result);

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) {
alert(results);
} else {
results;
}

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

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

//alert(results);
results;

… or I end up getting both:

alert(results);
results;

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