Javascript Firefox 安全错误:“操作不安全。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35042340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:12:41  来源:igfitidea点击:

Firefox SecurityError: "The operation is insecure."

javascripthtmlfirefoxbackbone.jscors

提问by Om3ga

I am using Backbone.LocalStorageplugin with backbone app. It is working fine in chrome and safari however, it is giving me below error in firefox.

我正在使用Backbone.LocalStorage插件和主干应用程序。它在 chrome 和 safari 中运行良好,但是,它在 Firefox 中给了我以下错误。

DOMException [SecurityError: "The operation is insecure." code: 18 nsresult: 0x80530012 location: http://localhost:8000/js/libs/backbone.localStorage/backbone.localStorage.js?version=1453910702146:137]

DOMException [SecurityError: “操作不安全。” 代码:18 nsresult:0x80530012 位置:http://localhost:8000/js/libs/backbone.localStorage/backbone.localStorage.js?version=1453910702146:137]

I am using python simpleHttpServer

我正在使用蟒蛇 simpleHttpServer

How can I resolve this error?

我该如何解决这个错误?

UPDATE

更新

Here is my code.

这是我的代码。

paths: {
    'jquery'        : 'libs/jquery/dist/jquery',
    'underscore'    : 'libs/underscore/underscore',
    'backbone'      : 'libs/backbone/backbone',
    'localStorage'  : 'libs/backbone.localStorage/backbone.localStorage',
    'text'          : 'plugins/text'
}

Here is collection where localStorage is used.

这是使用 localStorage 的集合。

var Items = Backbone.Collection.extend({

    model: SomeModel,

    localStorage: new Backbone.LocalStorage('items'),
});

UPDATE 2

更新 2

I am using firefox 36.

我正在使用 Firefox 36。

UPDATE 3

更新 3

It seems like it is a CORS issue but my firefox version is 36. Which should be fine.

似乎是 CORS 问题,但我的 Firefox 版本是 36。应该没问题。

UPDATE 4

更新 4

I am also getting this error in firefox nightly version 44. I also updated my firefox to version 44. Still same error.

我也在 firefox nightly version 44 中收到此错误。我还将我的 firefox 更新到 version 44。仍然是同样的错误。

回答by Daniel

Make sure Firefox has cookies enabled. The setting can be found under Menu/Options/Privacy/History

确保 Firefox 已启用 cookie。该设置可以在菜单/选项/隐私/历史记录下找到

In the dropdown, select either 'Remember History' or if You prefer use custom settings for history, but select option Accept cookies from sites

在下拉列表中,选择“记住历史记录”,或者如果您更喜欢使用历史记录的自定义设置,但选择选项接受来自站点的 cookie

Hope it helps.

希望能帮助到你。

回答by mkebri

This happens when we try to access a resource (CSS...) that is located on a different domain. To deal with this error we can use this:

当我们尝试访问位于不同域中的资源 (CSS...) 时,就会发生这种情况。为了处理这个错误,我们可以使用这个:

                   try {
                     //your critical access to ressources !
                     //rules = document.styleSheets[i].cssRules;
                        } catch(e) {
                   if(e.name !== "SecurityError") {
                       throw e;
                       }

回答by Venkat.R

Make sure your domains are same. verify Same Origin Policywhich means same domain, subdomain, protocol (http vs https) and same port.

确保您的域相同。验证同源策略,这意味着相同的域、子域、协议(http 与 https)和相同的端口。

What is Same Origin Policy?
How does pushState protect against potential content forgeries?

什么是同源政策?
pushState 如何防止潜在的内容伪造?

回答by Jitendra

I had similar issue with one script, I dig into error and found it required SSL websockets, so I started SSL and again checked, and It worked. Try enabling HTTPS and access website as https://127.0.0.1/It may solve error.

我在一个脚本上遇到了类似的问题,我深入研究了错误并发现它需要 SSL websockets,所以我启动了 SSL 并再次检查,它工作正常。尝试启用 HTTPS 并以https://127.0.0.1/访问网站它可能会解决错误。