Skip to content

Commit

Permalink
Merge pull request #18706 from storybookjs/run-interactions-condition…
Browse files Browse the repository at this point in the history
…ally

Interactions: Run conditionally based on query param
  • Loading branch information
shilman committed Aug 2, 2022
2 parents e95109b + 98ec2ab commit c6d9ea9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions code/lib/instrumenter/src/instrumenter.ts
Expand Up @@ -601,8 +601,19 @@ export function instrument<TObj extends Record<string, any>>(
options: Options = {}
): TObj {
try {
// Don't do any instrumentation if not loaded in an iframe.
if (global.window.parent === global.window) return obj;
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 unless it's forced - instrumentation can also be skipped.
if ((global.window.parent === global.window && !forceInstrument) || skipInstrument) {
return obj;
}

// Only create an instance if we don't have one (singleton) yet.
if (!global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__) {
Expand Down
1 change: 1 addition & 0 deletions docs/configure/features-and-behavior.md
Expand Up @@ -56,3 +56,4 @@ You can use URL parameters to configure some of the available features:
| **showPanel** | `panel` | `false`, `right`, `bottom` |
| **selectedPanel** | `addonPanel` | Any panel ID |
| **showTabs** | `tabs` | `true` |
| --- | `instrument` | `false`, `true` |

0 comments on commit c6d9ea9

Please sign in to comment.