Closed marina-mosti closed 4 years ago
I"d expect that to work. We're using window
in .storybook/preview.js
here:
https://github.com/storybookjs/storybook/blob/next/examples/angular-cli/.storybook/preview.ts#L9
which calls
@shilman Thanks for the reply I tried doing:
window.test = 'test'
console.log('window', window, window.test)
The window
object logged in the console definetly has a test
property, but when you try to access it from the global scope of the console, or from within the app it is not defined
@marina-mosti storybook contains the main window (aka "manager") and an iframe where the stories are rendered (aka "preview"). when set window.test
in preview it should be available in all your stories. if you're trying to access it from the console, make sure that the console is set to the iframe:
@shilman Thanks a ton for your help :)
Wow, that makes sense!
Is it possible to add this in the global variable documentation? Like, with the screenshot? We are so used to just open the console and be able to use it to access "global" variables that the possibility that its an iframe does not cross our mind...
Like, I've tryied follow what was said here https://storybook.js.org/docs/react/essentials/toolbars-and-globals but in the end this issue here gave me the answer: my global variables do exist, I just checking them on the wrong place :)
Cheers and great work!
@jonniebigodes
Describe the bug Within storybook I am unable to set a window variable.
We have i18n data that is set on a
window.i18n
variable. Storybook seems to prevent setting window variables, or overrides them. The documentation doesn't really specify at which point this could be/should be done.To Reproduce Steps to reproduce the behavior:
window.test = 'hi'
inpreview.js
or in a script tag in the headerExpected behavior
window.test
should be defined and accessible to the storiesScreenshots If applicable, add screenshots to help explain your problem.
Code snippets If applicable, add code samples to help explain your problem.
System:
Additional context Add any other context about the problem here.