【发布时间】:2012-07-19 03:53:15
【问题描述】:
此答案指定解释如何访问 gmail.com https://stackoverflow.com/a/9439525/222236 上所有 iframe 的内容
但是在 mail.google.com 上它会抛出这个错误:
Unsafe JavaScript attempt to access frame with URL https://plus.google.com/u/0/_/... from frame with URL https://mail.google.com/mail/u/0/#inbox. Domains, protocols and ports must match.
我尝试将*://plus.google.com/* 添加到扩展程序清单的匹配项中,但没有帮助。
更新:在访问内容之前检查 url 有效,但目前我的逻辑非常粗略,因为它只检查 google plus:
if(-1==iframes[i].src.indexOf('plus.google.com')) {
contentDocument = iframes[i].contentDocument;
if (contentDocument && !contentDocument.rweventsadded73212312) {
// add poller to the new iframe
checkForNewIframe(iframes[i].contentDocument);
}
}
【问题讨论】:
-
我相信,在许多情况下,可能需要遍历所有子帧,并且从控制流中排除外部域会破坏应用程序的主要功能。因此,在 chrome 扩展的情况下,我建议用清单中的 content_scripts
"all_frames": true声明替换通过帧的循环,以及合并结果的可选逻辑(如有必要)。
标签: javascript google-chrome-extension gmail