I had some free time to dig around in code to see how some internals of SharePoint CSWP’s worked. One thing that I’ve always noticed but never looked into was the fact that when editing a SharePoint page there was often debugger output in the browsers debugger console. Microsoft put a routine in their code to check if the browser supports a debugger output option. For example, I do believe that console.log is not a standardized command and thus some browsers will break on this. MS code built a wrapper to check a large variety of browsers for debug output support. If that passes, it will check the following to see if output should be turned on:

Srch.U.get_$4h = function() {
    return Srch.U.isPageInEditMode() || Srch.ScriptApplicationManager.get_current().states["shipTrace"]
}

If the page is in edit mode, which I’m sure some of us have known, the output turns on. Interestingly there is also a flag that can be set to true to force logging to always be on. The issue with SharePoint Online is that this script is dynamically loaded and I could not find an entry point or callback setup to allow for shipTrace to be set to true before the ScriptApplicationManager initializes. This means that you will likely miss much of the output by the time you flip the switch. If however you just want tracing to always be on for your code only, you can just flip it on before you start working with the Srch namespace.

This would look similar to this, assuming that you already ensured that the Srch namespace was loaded using executeFunc or similar.

Srch.ScriptApplicationManager.get_current().states["shipTrace"] = true;

No Comments

There are no comments related to this article.

Leave a Reply

Your email address will not be published. Required fields are marked *