Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upjest : SecurityError: localStorage is not available for opaque origins #2304
Comments
This comment has been minimized.
This comment has been minimized.
Summary of below discussion:
Transcription of below comment on the question of whether this is a "breaking change", which has since been hidden by GitHub's "see more comments" feature: Thanks, but as of this time I don't believe that's the best path forward. It isn't a breaking change for jsdom to implement new web platform features; that's a minor version. It's possible for dependents, even widely-used dependents, to write unfortunate code that detects new features and throws an exception if they appear. I hope we can all agree that even if such dependents exist, jsdom should not forever give up on adding new features in minor releases. The situation here is not quite that drastic, but seems to be similar. I haven't seen anyone track down the offending Jest code yet, so it's hard to say exactly, but it appears they're performing an operation which is explicitly broken by the normal course of jsdom development, and which would not work in a web browser that implements localStorage. I realize this is a hard situation for those of you impacted, by no fault of your own, by an unfortunate interaction regarding how your direct dependency is (ab)using your indirect dependency. But I'm hopeful this can be addressed at the right level, of fixing Jest's buggy code, instead of removing a useful feature from all jsdom users due to one dependent's bugs. Original reply to the OP, for context: It seems likely you are not setting a URL in your tests, but you, or perhaps Jest, are accessing |
This comment has been minimized.
This comment has been minimized.
dmitrizzle
commented
Jul 27, 2018
This is a very recent issue that seems to have popped up with |
This comment has been minimized.
This comment has been minimized.
ben-mckernan
commented
Jul 27, 2018
Yes, I started having the issue after upgrading from |
This comment has been minimized.
This comment has been minimized.
gokulkrishh
commented
Jul 27, 2018
@ben-mckernan Hi, What's the URL you gave to fix this ?? |
This comment has been minimized.
This comment has been minimized.
ben-mckernan
commented
Jul 27, 2018
@gokulkrishh I set it to |
This comment has been minimized.
This comment has been minimized.
I guess this is probably Enzyme-specific, because Enzyme does the thing that the jsdom docs explicitly warn not to do? Not too surprising that broke on a minor release, unfortunately :( |
This comment was marked as spam.
This comment was marked as spam.
justinkchen
commented
Jul 27, 2018
This broke for me too :( |
This comment has been minimized.
This comment has been minimized.
gokulkrishh
commented
Jul 27, 2018
@ben-mckernan Thanks |
This comment was marked as spam.
This comment was marked as spam.
miamollie
commented
Jul 27, 2018
Also experiencing this. jsdom/lib/jsdom/browser/Window.js Line 255 in 23d67eb |
This comment has been minimized.
This comment has been minimized.
("+1" comments will be marked as spam; emailing everyone in the issue thread is not helpful.) |
This comment has been minimized.
This comment has been minimized.
miamollie
commented
Jul 27, 2018
Apologies. Just trying to help. Can confirm adding And we are using Enzyme too, if that helps confirm your intuition. |
This comment has been minimized.
This comment has been minimized.
bencefr
commented
Jul 27, 2018
For electron app test I just set it to "file:/" which also works. |
This comment has been minimized.
This comment has been minimized.
gokulkrishh
commented
Jul 27, 2018
•
@miamollie I added |
This comment has been minimized.
This comment has been minimized.
ben-mckernan
commented
Jul 27, 2018
@domenic I am only using jest. So I'm not sure that it is an enzyme issue. |
This comment has been minimized.
This comment has been minimized.
miamollie
commented
Jul 27, 2018
@gokulkrishh Yeah, same, it stopped the localStorage security error but made some other tests fail. |
This comment has been minimized.
This comment has been minimized.
@ben-mckernan solution fixed it. Thanks! |
kitmoovup
closed this
Jul 27, 2018
Jul 27, 2018
This was referenced
csvan
referenced this issue
Jul 27, 2018
Closed
JSDom 11.12 causes SecurityError: localStorage is not available for opaque origins #6766
This comment has been minimized.
This comment has been minimized.
DcsMarcRemolt
commented
Jul 27, 2018
@ben-mckernan I'm using jest in an angular setup (with jest-preset-angular), same bug, same solution. So it is not an enzyme problem. |
This comment has been minimized.
This comment has been minimized.
csvan
commented
Jul 27, 2018
•
Seems like Jest needs to change the default value of |
creamidea
referenced this issue
Jul 27, 2018
Closed
SecurityError: localStorage is not available for opaque origins #6769
This comment has been minimized.
This comment has been minimized.
gokulkrishh
commented
Jul 27, 2018
•
@DcsMarcRemolt I was just debugging the issue. |
Jul 27, 2018
This was referenced
This comment has been minimized.
This comment has been minimized.
I'll reopen this issue to give it more visibility. See the first comment from Domenic for a solution. |
Zirro
reopened this
Jul 27, 2018
Zirro
referenced this issue
Jul 27, 2018
Merged
Implement Web storage - localStorage, sessionStorage, StorageEvent #2076
added a commit
to echo-health/node-grpc-interceptors
that referenced
this issue
Nov 19, 2018
This comment has been minimized.
This comment has been minimized.
Shreya1417
commented
Nov 21, 2018
"jest": { |
This comment has been minimized.
This comment has been minimized.
christian-draeger
commented
Nov 22, 2018
•
you can also add this to the affected test if jsdom is not needed there /**
* @jest-environment node
*/
it('my test', () => {
expect(2 + 2).toBe(4);
}); |
added a commit
to AKSW/building-navigator
that referenced
this issue
Nov 28, 2018
added a commit
to noscripter/mobx-react
that referenced
this issue
Nov 30, 2018
added a commit
to genejones/reportsuites.com
that referenced
this issue
Dec 5, 2018
Dec 13, 2018
This was referenced
added a commit
to ProdPerfect/prodperfect-keen-tracking.js
that referenced
this issue
Dec 19, 2018
willscripted
referenced this issue
Dec 19, 2018
Open
Fix localstorage not available errors in test suite #33
added a commit
to vuejs/vue-cli
that referenced
this issue
Dec 28, 2018
JPRightmove
referenced this issue
Jan 2, 2019
Merged
Components/Notify: add default prop for notifications #34
added a commit
to AminoJS/Amino.JS
that referenced
this issue
Jan 3, 2019
This comment has been minimized.
This comment has been minimized.
mscottx88
commented
Jan 8, 2019
I tested both options:
/**
* @jest-environment node
*/
"jest": {
"testURL": "http://localhost/"
} Both options worked. |
obensource
referenced this issue
Jan 15, 2019
Merged
Update package-lock to alleviate 'merge' package vulnerability #190
renoirb
referenced this issue
Jan 17, 2019
Open
Can't compile when using Jest and some code seems to require window.localStorage #14
poshaughnessy
referenced this issue
Jan 17, 2019
Open
Fix for SecurityError when running npm run test #1
This comment has been minimized.
This comment has been minimized.
fbaholli
commented
Jan 26, 2019
•
I had it work by adding in the package.json file:
|
kitmoovup commentedJul 27, 2018
•
edited
When I run a
jest
with my test cases. It shows the following error when I upgrade the package. In my test cases, there is no localStorage is used. How can I fix this problem?