What is the best way to detect if running in a Dashboard or Web Report?

What is the best way to detect if my JavaScript and/or Session Relevance is running in a Dashboard or Web Report when the exact same code is run in both? ( Introspection & Reflection )

In most cases, the exact same HTML & JavaScript & Session Relevance works within a Dashboard & a Web Report. This is quite useful to be able to share the same code base between them.

The issue is that there are slightly different capabilities on the edges between Web Reports and BigFix Console Dashboards. If I can properly detect if I am in a web reports context instead of a console context, I could not show certain UI and options that would only work in the console and vis versa.

There is also an added complexity of differentiating between a Wizard from an external site vs a Wizard from a custom site vs a Wizard loaded using the load wizard option in the console debug menu.

Eventually, there will also be the added possibility of code being shared between Dashboards / Wizards / Web Reports and the WebUI, so that would be another context to detect and handle.


One option:

Different javascript functions are loaded by wizards.js in WebReports vs Console Dashboards. I could detect which is the case by looking for functions that only exist in one or the other to tell which context my code is running within.

One problem with this option is that it is possible for more functions to be added over time to either Web Reports or the Console, and for them to change names. Name changes are unlikely since it would likely break existing functionality, but you never know.

The other problem with this option is that if I or others ever take the time to polyfill or write custom JavaScript to fill in the missing pieces on either side, then this method won’t work as well. I don’t know that I’ll ever get around to doing this, but definitely something that I’ve thought of doing.

Another Option:

Check to see if “Console Only” session relevance is available. This seems like the better option, since it seems less likely to change as drastically over time. It would involve running a session relevance query to see if console only session relevance is available, and if so, then infer that it must be running within the console context.

Other options?

Perhaps there is something even more straightforward that I am missing. It would be nice if there was a direct method to finding out the actual context.

The current wizard and in web reports context inspectors seem like they would fulfill this role.

Also in console context from @JasonWalker below.


References:

Related:

I also see a property in console context that might be the inverse of in web reports context

1 Like