Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactions: Run conditionally based on query param #18706

Merged
merged 5 commits into from Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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` |