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
Changes from 2 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
9 changes: 7 additions & 2 deletions lib/instrumenter/src/instrumenter.ts
Expand Up @@ -584,8 +584,13 @@ 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;
// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work in IE? Not sure a polyfill is generated.

if (!params.get('interactions')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!params.get('interactions')) {
if (!params.get('instrument')) {

It's not just for interactions, and interactions suggests it would enable/disable the actual interactions which it doesn't.

I'm thinking perhaps we should support the inverse as well. So if you set instrument=false then instrumentation will be disabled even if loaded within an iframe. In other words, the instrument param is respected (true or false), and if not specified we'll fall back to the window.parent check.

return obj;
}
}

// Only create an instance if we don't have one (singleton) yet.
if (!global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__) {
Expand Down