来自 Facebook 和跨域消息传递的 SecurityError
SecurityError from Facebook and Cross Domain Messaging
我们有一个利用 facebook javascript sdk 和登录功能的应用程序。
我们注意到生产日志中出现了这个错误。专门针对 iOS 版本为 10.3 及更高版本的设备。似乎也只针对 safari 浏览器
SecurityError (DOM Exception 18): Blocked a frame with origin
"https://www.mymadeupsite.com" from accessing a frame with origin
"https://staticxx.facebook.com". The frame being accessed set
"document.domain" to "facebook.com", but the frame requesting access
did not. Both must set "document.domain" to the same value to allow
access.
这是我们的初始化函数:
init: function(options) {
var facebookUrl, scriptInclude;
Facebook.baseHost = options.baseHost;
if (typeof FB !== "undefined" && FB !== null) {
return Facebook.setup();
} else {
if (options.appId == null) {
throw 'Facebook: cannot init without appId';
}
window.fbAsyncInit = function() {
FB.init({
appId: options.appId,
version : 'v2.3',
channelUrl: options.channelUrl || ("" + document.location.protocol + "//" + document.location.host + "/channel.html"),
status: true,
cookie: false,
xfbml: false,
oauth: true
});
return Facebook.setup();
};
$('body').append('<div id="fb-root"></div>');
facebookUrl = "//connect.facebook.net/" + (Facebook.getLocaleFacebookSupports(Social.SETTINGS.fbLocale)) + "/sdk.js";
scriptInclude = "<script type=\"text/javascript\" async=\"true\" src=\"" + facebookUrl + "\"></script>";
return $('#fb-root').append(scriptInclude);
}
}
我的问题是,为什么我们只在 iOS 设备和版本 10.3 上收到此错误?
我也 运行 解决了这个问题,在仔细研究之后,它似乎是浏览器自动填充中的一个错误:发送到我们的日志集群的堆栈跟踪如下所示:
g@https://example.com:5:190,
g@https://example.com:7:323,
extractNewForms@https://example.com:13:37,
extractForms@https://example.com:8:381,
global code@https://example.com:1:98
如您所见,错误发生在 extractForms
函数的某处,(对我们而言)代码库中的任何地方都不存在。 Google 搜索显示 extractForms
和 extractNewForms
都是浏览器自动填充库的一部分,线程 here 表明其中存在错误(评论 12 和 15与您的问题最相关)。
据我所知,这也与 Facebook 没有特别相关:在我们的日志中,我们看到更多 iframe 的类似错误,包括来自我们自己控制的(子)域的 iframe。
不幸的是,我不知道任何修复或解决方法,而且我也非常怀疑(用户空间)fix/workaround 是否真的可行。我认为你唯一能做的就是忽略这些错误。
我们有一个利用 facebook javascript sdk 和登录功能的应用程序。
我们注意到生产日志中出现了这个错误。专门针对 iOS 版本为 10.3 及更高版本的设备。似乎也只针对 safari 浏览器
SecurityError (DOM Exception 18): Blocked a frame with origin "https://www.mymadeupsite.com" from accessing a frame with origin "https://staticxx.facebook.com". The frame being accessed set "document.domain" to "facebook.com", but the frame requesting access did not. Both must set "document.domain" to the same value to allow access.
这是我们的初始化函数:
init: function(options) {
var facebookUrl, scriptInclude;
Facebook.baseHost = options.baseHost;
if (typeof FB !== "undefined" && FB !== null) {
return Facebook.setup();
} else {
if (options.appId == null) {
throw 'Facebook: cannot init without appId';
}
window.fbAsyncInit = function() {
FB.init({
appId: options.appId,
version : 'v2.3',
channelUrl: options.channelUrl || ("" + document.location.protocol + "//" + document.location.host + "/channel.html"),
status: true,
cookie: false,
xfbml: false,
oauth: true
});
return Facebook.setup();
};
$('body').append('<div id="fb-root"></div>');
facebookUrl = "//connect.facebook.net/" + (Facebook.getLocaleFacebookSupports(Social.SETTINGS.fbLocale)) + "/sdk.js";
scriptInclude = "<script type=\"text/javascript\" async=\"true\" src=\"" + facebookUrl + "\"></script>";
return $('#fb-root').append(scriptInclude);
}
}
我的问题是,为什么我们只在 iOS 设备和版本 10.3 上收到此错误?
我也 运行 解决了这个问题,在仔细研究之后,它似乎是浏览器自动填充中的一个错误:发送到我们的日志集群的堆栈跟踪如下所示:
g@https://example.com:5:190,
g@https://example.com:7:323,
extractNewForms@https://example.com:13:37,
extractForms@https://example.com:8:381,
global code@https://example.com:1:98
如您所见,错误发生在 extractForms
函数的某处,(对我们而言)代码库中的任何地方都不存在。 Google 搜索显示 extractForms
和 extractNewForms
都是浏览器自动填充库的一部分,线程 here 表明其中存在错误(评论 12 和 15与您的问题最相关)。
据我所知,这也与 Facebook 没有特别相关:在我们的日志中,我们看到更多 iframe 的类似错误,包括来自我们自己控制的(子)域的 iframe。
不幸的是,我不知道任何修复或解决方法,而且我也非常怀疑(用户空间)fix/workaround 是否真的可行。我认为你唯一能做的就是忽略这些错误。