Chrome webkit 检查器中不断生成“不安全的 JavaScript 尝试使用 URL 访问框架...”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3010170/
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 02:53:50  来源:igfitidea点击:

"Unsafe JavaScript attempt to access frame with URL..." error being continuously generated in Chrome webkit inspector

javascriptfacebookgoogle-chromewebkitfacebook-opengraph

提问by Neil Sarkar

Chrome (or any other webkit browser) throws a ton of these "Unsafe JavaScript attempt to access frame with URL..." when working with the Facebook API for example.

例如,当使用 Facebook API 时,Chrome(或任何其他 webkit 浏览器)会抛出大量这些“不安全的 JavaScript 尝试使用 URL 访问框架...”。

It doesn't interfere with actual operation, but it does make the javascript console basically unusable.

它不会干扰实际操作,但它确实使 javascript 控制台基本无法使用。

I'd like to know if there is a way to suppress these errors specifically in the console? Or if there are other solutions you guys can think of, I would really appreciate it.

我想知道是否有办法专门在控制台中抑制这些错误?或者,如果你们能想到其他解决方案,我将不胜感激。

Thanks.

谢谢。

采纳答案by Dagg Nabbit

You could allow cross-domain requests during testing by running chrome with the --disable-web-securitycommand line option. This should probably get rid of the error (and allow FB to spy on your testing ;)

您可以在测试期间通过使用--disable-web-security命令行选项运行 chrome 来允许跨域请求。这应该可以消除错误(并允许 FB 监视您的测试;)

回答by Celli

This happens when a source from an different domain is loaded and tries to access the document.cookie. It happens with head sources (script tags) as well with iframe documents which try to access the document.cookie for some reason.

当加载来自不同域的源并尝试访问 document.cookie 时,就会发生这种情况。它发生在头源(脚本标签)以及 iframe 文档中,这些文档出于某种原因尝试访问 document.cookie。

回答by Zach Lysobey

Whats the problem?

有什么问题?

Tons of Unsafe JavaScript attempt to access frame with URL...error messages in the Chrome JS console.

Unsafe JavaScript attempt to access frame with URL...Chrome JS 控制台中的大量错误消息。

As @thechrisproject points out, these errors are caused by many reputable 3rd party api's and widgets, including but not limited to:

正如@thechrisproject 指出的那样,这些错误是由许多著名的 3rd 方 api 和小部件引起的,包括但不限于:

  • The Facebook JS SDK
  • Vimeo Iframe Embed
  • Google Maps Iframe Embed
  • Facebook JS SDK
  • Vimeo Iframe 嵌入
  • 谷歌地图 iframe 嵌入

My understanding on the why:(please correct me if I'm wrong)

我对原因的理解:(如果我错了,请纠正我)

Chrome has stricter security settings and/or shows more such errors than competing browsers. API/widget/embed authors attempt to do things (cross-domain/frame) that will not work in all browsers (probably for their own reporting/analytics) but that don't actually effect the usuabilty of their widget if it doesn't work (just causes a lot of annoying errors)

与竞争浏览器相比,Chrome 具有更严格的安全设置和/或显示更多此类错误。API/widget/embed 作者试图做一些在所有浏览器中都不起作用的事情(跨域/框架)(可能是为了他们自己的报告/分析),但如果没有的话,实际上不会影响他们的小部件的可用性工作(只会导致很多烦人的错误)

Quick Answer

快速回答

NO,you cannot (just) suppress these errors in the chrome console.

不,您不能(只是)在 chrome 控制台中抑制这些错误。

Solutions?

解决方案?

  • Deal with it.These errors do not actually break these 3rd party apis and widgets, they just make the console much more difficult to use
  • you can set the console to log only Warnings, Logs, or Debug messages. This will hide ALL errors.
  • you can use another browser
  • As @Dagg_Nabbit. pointed out, you can allow cross-domain requests by running chrome with the --disable-web-securitycommand line option. More information here: Disable same origin policy in Chrome. Note that this setting will negatively effect the security of your browser. I have 2 chrome shortcuts so I can open it with or without this flag.
  • 处理它。这些错误实际上并没有破坏这些 3rd 方 api 和小部件,它们只是使控制台更难使用
  • 您可以将控制台设置为仅记录警告、日志或调试消息。这将隐藏所有错误。
  • 您可以使用其他浏览器
  • 作为@Dagg_Nabbit。指出,您可以通过使用--disable-web-security命令行选项运行 chrome 来允许跨域请求。此处的更多信息:在 Chrome 中禁用同源策略。请注意,此设置将对浏览器的安全性产生负面影响。我有 2 个 chrome 快捷方式,所以我可以在有或没有这个标志的情况下打开它。

回答by Jhourlad Estrella

Since we can't blame the people from Google for constructing such a safe browser, I think the best solution is to use Facebook's server-side solutions (e.g. PHP SDK), it'll save you a lot, lot, lot, lot, lot of headache. The only advantage I see in using the FB javascript SDK is the popup login which you can do yourself using javascript/jQuery.

既然我们不能责怪 Google 的人构建了这样一个安全的浏览器,我认为最好的解决方案是使用 Facebook 的服务器端解决方案(例如 PHP SDK),它会为您节省很多很多很多很多,很头疼。我在使用 FB javascript SDK 时看到的唯一优势是弹出式登录,您可以使用 javascript/jQuery 自己完成。

回答by Rob H

These errors can be thrown if, when you register your app with Facebook, you don't have a trailing forward slash in the Site URL field. In other words, you need "http://domain.com/" not "http://domain.com"

如果在 Facebook 注册应用程序时,站点 URL 字段中没有尾随正斜杠,则可能会引发这些错误。换句话说,您需要“ http://domain.com /”而不是“ http://domain.com

You can check the Site URL setting from developers.facebook.com/appsEdit settings -> Basic -> Site URL.

您可以从developer.facebook.com/apps编辑设置 -> 基本 -> 站点 URL检查站点 URL 设置。