question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to set window variables

See original GitHub issue

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:

  1. Set window.test = 'hi' in preview.js or in a script tag in the header
  2. Check the console and window.test is undefined

Expected behavior window.test should be defined and accessible to the stories

Screenshots If applicable, add screenshots to help explain your problem.

Code snippets If applicable, add code samples to help explain your problem.

System:

Environment Info:

  System:
    OS: macOS 10.15.5
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 12.18.0 - ~/.nvm/versions/node/v12.18.0/bin/node
    Yarn: 1.22.4 - ~/.npm-global/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v12.18.0/bin/npm
  Browsers:
    Chrome: 83.0.4103.116
    Firefox: 77.0.1
    Safari: 13.1.1
  npmPackages:
    @storybook/addon-a11y: ^5.3.19 => 5.3.19
    @storybook/addon-actions: ^5.3.19 => 5.3.19
    @storybook/addon-centered: ^5.3.19 => 5.3.19
    @storybook/addon-knobs: ^5.3.19 => 5.3.19
    @storybook/addon-links: ^5.3.19 => 5.3.19
    @storybook/addon-notes: ^5.3.19 => 5.3.19
    @storybook/addons: ^5.3.19 => 5.3.19
    @storybook/vue: ^5.3.19 => 5.3.19

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
shilmancommented, Jul 1, 2020

@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:

Addon___Controls_-_Basic_⋅_Storybook
1reaction
marina-mosticommented, Jul 2, 2020

@shilman Thanks a ton for your help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't edit environment variables in windows 10
I got around it by opening the System page in Control Panel (Win+X -> Y), going to "Advanced system settings", then clicking "Environment ......
Read more >
The Windows 10 has a problem – it can't set path properly ...
In system, select “Advanced system settings”. Page 2. 4. Select “Environment Variables”. 5. Pick the system variable “Path” and select “Edit”. Page 3 ......
Read more >
Create React App - Unable to set window object before test runs
I'm looking for a way to set this window variable before the tests run (or a better way to structure the way I'm...
Read more >
{ Fixed } : Environment Variable is disabled? Can't ... - YouTube
hey guys, in this video, i am explaining how to fix environment variable is disabled.
Read more >
I am admin, but I cannot edit system variables (Windows 10)
If you don't choose this option, the system variables buttons New... , Edit... and Delete will be greyed out as in your screenshot....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found