@@ -270,13 +270,15 @@ export class KnockGuideClient {
270270 ) {
271271 const {
272272 trackLocationFromWindow = true ,
273+ // TODO: Remove this option once we ship guide toolbar v2, and offload
274+ // as much debugging specific logic and responsibilities to toolbar.
275+ trackDebugParams = false ,
273276 throttleCheckInterval = DEFAULT_COUNTER_INCREMENT_INTERVAL ,
274277 } = options ;
275278 const win = checkForWindow ( ) ;
276279
277280 const location = trackLocationFromWindow ? win ?. location ?. href : undefined ;
278-
279- const debug = detectDebugParams ( ) ;
281+ const debug = trackDebugParams ? detectDebugParams ( ) : undefined ;
280282
281283 this . store = new Store < StoreState > ( {
282284 guideGroups : [ ] ,
@@ -412,8 +414,8 @@ export class KnockGuideClient {
412414 const params = {
413415 ...this . targetParams ,
414416 user_id : this . knock . userId ,
415- force_all_guides : debugState . forcedGuideKey ? true : undefined ,
416- preview_session_id : debugState . previewSessionId || undefined ,
417+ force_all_guides : debugState ? .forcedGuideKey ? true : undefined ,
418+ preview_session_id : debugState ? .previewSessionId || undefined ,
417419 } ;
418420
419421 const newChannel = this . socket . channel ( this . socketChannelTopic , params ) ;
@@ -561,6 +563,39 @@ export class KnockGuideClient {
561563 }
562564 }
563565
566+ setDebug ( debugOpts ?: Omit < DebugState , "debugging" > ) {
567+ this . knock . log ( "[Guide] .setDebug()" ) ;
568+ const shouldRefetch = ! this . store . state . debug ?. debugging ;
569+
570+ this . store . setState ( ( state ) => ( {
571+ ...state ,
572+ debug : { ...debugOpts , debugging : true } ,
573+ } ) ) ;
574+
575+ if ( shouldRefetch ) {
576+ this . knock . log (
577+ `[Guide] Start debugging, refetching guides and resubscribing to the websocket channel` ,
578+ ) ;
579+ this . fetch ( ) ;
580+ this . subscribe ( ) ;
581+ }
582+ }
583+
584+ unsetDebug ( ) {
585+ this . knock . log ( "[Guide] .unsetDebug()" ) ;
586+ const shouldRefetch = this . store . state . debug ?. debugging ;
587+
588+ this . store . setState ( ( state ) => ( { ...state , debug : undefined } ) ) ;
589+
590+ if ( shouldRefetch ) {
591+ this . knock . log (
592+ `[Guide] Stop debugging, refetching guides and resubscribing to the websocket channel` ,
593+ ) ;
594+ this . fetch ( ) ;
595+ this . subscribe ( ) ;
596+ }
597+ }
598+
564599 //
565600 // Store selector
566601 //
@@ -924,7 +959,7 @@ export class KnockGuideClient {
924959 // Get the next unarchived step.
925960 getStep ( ) {
926961 // If debugging this guide, return the first step regardless of archive status
927- if ( self . store . state . debug . forcedGuideKey === this . key ) {
962+ if ( self . store . state . debug ? .forcedGuideKey === this . key ) {
928963 return this . steps [ 0 ] ;
929964 }
930965
@@ -981,7 +1016,7 @@ export class KnockGuideClient {
9811016
9821017 // Append debug params
9831018 const debugState = this . store . state . debug ;
984- if ( debugState . forcedGuideKey ) {
1019+ if ( debugState ? .forcedGuideKey || debugState ?. debugging ) {
9851020 combinedParams . force_all_guides = true ;
9861021 }
9871022
@@ -1150,8 +1185,15 @@ export class KnockGuideClient {
11501185
11511186 this . knock . log ( `[Guide] Detected a location change: ${ href } ` ) ;
11521187
1188+ if ( ! this . options . trackDebugParams ) {
1189+ this . setLocation ( href ) ;
1190+ return ;
1191+ }
1192+
1193+ // TODO: Remove below once we ship toolbar v2.
1194+
11531195 // If entering debug mode, fetch all guides.
1154- const currentDebugParams = this . store . state . debug ;
1196+ const currentDebugParams = this . store . state . debug || { } ;
11551197 const newDebugParams = detectDebugParams ( ) ;
11561198
11571199 this . setLocation ( href , { debug : newDebugParams } ) ;
0 commit comments