我一直致力于Chrome扩展程序,只是为了获得一些乐趣,并尝试学习更多的javascript来为Google Buzz帖子添加+1按钮。
我认为我遇到了“不安全的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”中,所以我尝试将加号一个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 未捕获的TypeError:无法读取null的属性'src'
不安全的JavaScript尝试使用URL访问框架 来自框架的https://mail.google.com/mail/#buzz来自URL /apps-static//js/nw/nw_i/rt=h/ver=H-Y4RtFct_c.en./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 /。域,协议和端口必须匹配