我一直在开发 chrome 扩展,只是为了找点乐子,并尝试学习更多的 javascript 以将 +1 按钮添加到 Google Buzz 帖子中。
我想我遇到了“不安全的 JavaScript 尝试使用 URL 访问框架”错误/跨域问题。这是根据我的 chrome 控制台日志。
我的代码如下:
function addGJS() {
var po = document.createElement('script'); po.type = 'text/javascript';
po.src = 'https://apis.google.com/js/plusone.js';
po.innerHTML = '{"parsetags": "explicit"}';
jQuery(po).load (function() {
var items;
var startInt = setInterval(function() {
items = $("#canvas_frame").contents().find('.nH.h7.HY.aW');
if (items.length > 0) { clearInterval(startInt); main(items); }
}, 1000);
});
var insert;
var poInt = setInterval(function() {
insert = document.getElementById("canvas_frame");
if (insert != null) { insert.contentDocument.body.appendChild(po); clearInterval(poInt) }
}, 1000);
}
google Buzz 的主要内容出现在 iframe“canvas_frame”中,所以我尝试将 plus-one src 添加到其中。我进行了很好的搜索,但找不到任何明确的答案。我试图将 iframe 的类型更改为内容。我还阅读了有关 postMessage 的信息,但不确定在这种情况下是否可行?
或者我只是搞砸了?:)
干杯,
更新: manifest.json(我已取出的描述和图标):
"content_scripts": [
{
"js": [ "scripts/jquery.js", "scripts/plusone.js", "user_scripts/buzzplusone.js" ],
"matches": [ "*://*.google.com/*/#buzz", "*://google.com/*/#buzz", "https://mail.google.com/*" ],
"run_at": "document_end"
}],
"permissions": [ "https://mail.google.com/*", "https://plus.google.com/*" ],
我现在看到的 console.log 错误还有:
未捕获的 CustomError:受保护函数中的错误:SYNTAX_ERR:DOM 异常 12
googleapis.client__plusone.js:27 未捕获的类型错误:无法读取 null 的属性“src”
不安全的 JavaScript 尝试 从带有 URL /apps-static//js/nw/nw_i/rt=h/ver=H-Y4RtFct_c.en 的框架访问带有 URL https://mail.google.com/mail/#buzz的框架。 /am=!oHhtMCRDHb3v-YjahgnJviPf2CNHgPs1tsZl/d=1/">https://plus.google.com/ /apps-static/ /js/nw/nw_i/rt=h/ver=H-Y4RtFct_c.en./am =!oHhtMCRDHb3v-YjahgnJviPf2CNHgPs1tsZl/d=1/. 域、协议和端口必须匹配