@embrace-io/web-sdk
Version:
3 lines (2 loc) • 1.14 kB
JavaScript
import{EmbraceInstrumentationBase as i}from"../../EmbraceInstrumentationBase/EmbraceInstrumentationBase.js";class s extends i{constructor({diag:i,backgroundSessions:s=!1,visibilityDoc:e=window.document}={}){super({instrumentationName:"SpanSessionOnLoadInstrumentation",instrumentationVersion:"1.0.0",config:{},diag:i}),this._onVisibilityChange=()=>{this._diag.debug(`Visibility change detected: ${e.visibilityState}`),this.sessionManager.endSessionSpanInternal("state_changed"),"hidden"===e.visibilityState&&s?(this._diag.debug("Starting a session since document visibility switched to hidden and `backgroundSessions` is enabled"),this.sessionManager.startSessionSpan()):"visible"===e.visibilityState&&(this._diag.debug("Starting a session since document visibility switched to visible"),this.sessionManager.startSessionSpan())},this._config.enabled&&this.enable()}disable(){window.removeEventListener("visibilitychange",this._onVisibilityChange)}enable(){window.addEventListener("visibilitychange",this._onVisibilityChange)}}export{s as SpanSessionVisibilityInstrumentation};
//# sourceMappingURL=SpanSessionVisibilityInstrumentation.js.map