From 2f8d6eea324c8c1f717eefa1e5f1b8816e05ec2c Mon Sep 17 00:00:00 2001 From: Jono Kolnik <1164060+JonathanKolnik@users.noreply.github.com> Date: Wed, 13 Jul 2022 20:41:45 -0400 Subject: [PATCH 1/4] allow interactions to run conditionally when interactions query param is set --- lib/instrumenter/src/instrumenter.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/instrumenter/src/instrumenter.ts b/lib/instrumenter/src/instrumenter.ts index 86b5f64cc4b1..13b69a73851f 100644 --- a/lib/instrumenter/src/instrumenter.ts +++ b/lib/instrumenter/src/instrumenter.ts @@ -584,8 +584,10 @@ export function instrument>( options: Options = {} ): TObj { try { - // Don't do any instrumentation if not loaded in an iframe. - if (global.window.parent === global.window) return obj; + const params = new URLSearchParams(global.window.location.search); + + // Don't do any instrumentation if not loaded in an iframe and it's not running in a capture. + if (global.window.parent === global.window && !params.get('interactions')) return obj; // Only create an instance if we don't have one (singleton) yet. if (!global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__) { From f0af160785553b0ec19314d9a12c96a662714056 Mon Sep 17 00:00:00 2001 From: Jono Kolnik <1164060+JonathanKolnik@users.noreply.github.com> Date: Thu, 14 Jul 2022 10:31:33 -0400 Subject: [PATCH 2/4] Update instrumenter.ts --- lib/instrumenter/src/instrumenter.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/instrumenter/src/instrumenter.ts b/lib/instrumenter/src/instrumenter.ts index 13b69a73851f..b0cc76c9336d 100644 --- a/lib/instrumenter/src/instrumenter.ts +++ b/lib/instrumenter/src/instrumenter.ts @@ -584,10 +584,13 @@ export function instrument>( options: Options = {} ): TObj { try { - const params = new URLSearchParams(global.window.location.search); - // Don't do any instrumentation if not loaded in an iframe and it's not running in a capture. - if (global.window.parent === global.window && !params.get('interactions')) return obj; + if (global.window.parent === global.window) { + const params = new URLSearchParams(global.window.location.search); + if (!params.get('interactions')) { + return obj; + } + } // Only create an instance if we don't have one (singleton) yet. if (!global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__) { From 162a28f07467f359db8eb7f377e85c83512ae3e6 Mon Sep 17 00:00:00 2001 From: Jono Kolnik <1164060+JonathanKolnik@users.noreply.github.com> Date: Tue, 26 Jul 2022 11:54:48 -0400 Subject: [PATCH 3/4] force or skip instrumenting, make IE compatible, document query param --- docs/configure/features-and-behavior.md | 3 ++- lib/instrumenter/src/instrumenter.ts | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/configure/features-and-behavior.md b/docs/configure/features-and-behavior.md index d936e062d962..664fed9ec5e5 100644 --- a/docs/configure/features-and-behavior.md +++ b/docs/configure/features-and-behavior.md @@ -55,4 +55,5 @@ You can use URL parameters to configure some of the available features: | **showNav** | `nav` | `false` | | **showPanel** | `panel` | `false`, `right`, `bottom` | | **selectedPanel** | `addonPanel` | Any panel ID | -| **showTabs** | `tabs` | `true` | \ No newline at end of file +| **showTabs** | `tabs` | `true` | +| --- | `instrument` | `false`, `true` | \ No newline at end of file diff --git a/lib/instrumenter/src/instrumenter.ts b/lib/instrumenter/src/instrumenter.ts index b0cc76c9336d..02f6e24c1ac9 100644 --- a/lib/instrumenter/src/instrumenter.ts +++ b/lib/instrumenter/src/instrumenter.ts @@ -584,12 +584,18 @@ export function instrument>( options: Options = {} ): TObj { try { + let forceInstrument = false; + let skipInstrument = false; + + if (global?.window?.location?.search?.includes('instrument=true')) { + forceInstrument = true; + } else if (global?.window?.location?.search?.includes('instrument=false')) { + skipInstrument = true; + } + // Don't do any instrumentation if not loaded in an iframe and it's not running in a capture. - if (global.window.parent === global.window) { - const params = new URLSearchParams(global.window.location.search); - if (!params.get('interactions')) { - return obj; - } + if ((global.window.parent === global.window && !forceInstrument) || skipInstrument) { + return obj; } // Only create an instance if we don't have one (singleton) yet. From 98ec2ab04de660492f04738a828d8d9afdc42cd1 Mon Sep 17 00:00:00 2001 From: Jono Kolnik <1164060+JonathanKolnik@users.noreply.github.com> Date: Wed, 27 Jul 2022 09:09:16 -0400 Subject: [PATCH 4/4] Update instrumenter.ts --- code/lib/instrumenter/src/instrumenter.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/lib/instrumenter/src/instrumenter.ts b/code/lib/instrumenter/src/instrumenter.ts index a5e1c05bd220..ea41efe879c8 100644 --- a/code/lib/instrumenter/src/instrumenter.ts +++ b/code/lib/instrumenter/src/instrumenter.ts @@ -604,13 +604,13 @@ export function instrument>( let forceInstrument = false; let skipInstrument = false; - if (global?.window?.location?.search?.includes('instrument=true')) { + if (global.window.location?.search?.includes('instrument=true')) { forceInstrument = true; - } else if (global?.window?.location?.search?.includes('instrument=false')) { + } else if (global.window.location?.search?.includes('instrument=false')) { skipInstrument = true; } - // Don't do any instrumentation if not loaded in an iframe and it's not running in a capture. + // Don't do any instrumentation if not loaded in an iframe unless it's forced - instrumentation can also be skipped. if ((global.window.parent === global.window && !forceInstrument) || skipInstrument) { return obj; }