@embrace-io/web-sdk
Version:
3 lines (2 loc) • 1.3 kB
JavaScript
import{__extends as i}from"tslib";import{EmbraceInstrumentationBase as n}from"../../EmbraceInstrumentationBase/EmbraceInstrumentationBase.js";var e=function(n){function e(i){var e=void 0===i?{}:i,t=e.diag,s=e.backgroundSessions,a=void 0!==s&&s,o=e.visibilityDoc,d=void 0===o?window.document:o,r=n.call(this,{instrumentationName:"SpanSessionOnLoadInstrumentation",instrumentationVersion:"1.0.0",config:{},diag:t})||this;return r._onVisibilityChange=function(){r._diag.debug("Visibility change detected: ".concat(d.visibilityState)),r.sessionManager.endSessionSpanInternal("state_changed"),"hidden"===d.visibilityState&&a?(r._diag.debug("Starting a session since document visibility switched to hidden and `backgroundSessions` is enabled"),r.sessionManager.startSessionSpan()):"visible"===d.visibilityState&&(r._diag.debug("Starting a session since document visibility switched to visible"),r.sessionManager.startSessionSpan())},r._config.enabled&&r.enable(),r}return i(e,n),e.prototype.disable=function(){window.removeEventListener("visibilitychange",this._onVisibilityChange)},e.prototype.enable=function(){window.addEventListener("visibilitychange",this._onVisibilityChange)},e}(n);export{e as SpanSessionVisibilityInstrumentation};
//# sourceMappingURL=SpanSessionVisibilityInstrumentation.js.map