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
1 parent 20db22a commit 25e1c62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/configure/features-and-behavior.md
Expand Up @@ -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` |
| **showTabs** | `tabs` | `true` |
| --- | `instrument` | `false`, `true` |
15 changes: 13 additions & 2 deletions lib/instrumenter/src/instrumenter.ts
Expand Up @@ -543,8 +543,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

0 comments on commit 25e1c62

Please sign in to comment.