其他分享
首页 > 其他分享> > DOMException [SecurityError]: localStorage is not available for opaque origins

DOMException [SecurityError]: localStorage is not available for opaque origins

作者:互联网

jsdom补充document的环境

const jsdom = require("jsdom");
const {JSDOM} = jsdom;
const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`, {
  url: 'https://www.tiktok.com/'
});

window = dom.window;
window.localStorage = {}
document = window.document;
localStorage = window.localStorage;

完美解决localStorage的问题

localStorage的原理本来就是设置本地键值

因此在jsdom补充url的属性就可以了

参考地址:https://zhuanlan.zhihu.com/p/130969994

标签:available,DOMException,const,origins,window,localStorage,https,jsdom,document
来源: https://www.cnblogs.com/itBlogToYpl/p/15494860.html