开发者

Applying google plus one src to iframe in chrome extension

开发者 https://www.devze.com 2023-04-04 02:01 出处:网络
I\'ve been working on a chrome extension just for a bit of fun and trying to learn a bit more javascript to add the +1 button to Google Buzz posts.

I've been working on a chrome extension just for a bit of fun and trying to learn a bit more javascript to add the +1 button to Google Buzz posts.

I think I'm running into the "Unsafe JavaScript attempt to access frame with URL" error / Cross domain issue. That's according to my chrome console log.

My code is as follows:

    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);
}

The main content of google buzz appears in the iframe "canvas_frame" so I attempted to add the plus-one src to that. I've had a good search and can't find any definitive answers. I tried to change the type of the iframe to content.开发者_高级运维 I also read about postMessage but not sure if that is possible in this context?

or am I just screwed? :)

Cheers,

UPDATE: manifest.json (description and icons i've taken out):

"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/*" ],

Also the console.log errors i'm seeing now are:

  • Uncaught CustomError: Error in protected function: SYNTAX_ERR: DOM Exception 12

  • googleapis.client__plusone.js:27 Uncaught TypeError: Cannot read property 'src' of null

  • Unsafe JavaScript attempt to access frame with URL https://mail.google.com/mail/#buzz from frame with 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/. Domains, protocols and ports must match

0

精彩评论

暂无评论...
验证码 换一张
取 消