Radu Andrei
Radu Andrei

Reputation: 1073

include adsense(ads) in firefox extension

I'm trying to get google adds to show in my page using a firefox extension. I grabbed the code from //pagead2.googlesyndication.com/pagead/js/adsbygoogle.js and saved it in a local file.

On the page that i am trying to manipulate there is an element similar to this:

<ins xmlns="http://www.w3.org/1999/xhtml" class="adsbygoogle" style="display:inline-block;width:728px;height:90px;margin-top:10px" data-ad-client="ca-pub-XXX" data-ad-slot="XXX"></ins>

In my index.js file i have the following:

var tabs = require("sdk/tabs");
tabs.on('open', function(tab){
  var workerOpen = tab.attach({
    contentScriptFile: ["./js/addsbygoogle.js", "./js/content_script.js"]
  });
  workerOpen.port.emit('newTabOpened');
});

In my content_script.js i have this:

self.port.on('newTabOpened', function(){
    (adsbygoogle = window.adsbygoogle || []).push({});
})

I have set my permissions in package.JSON:

"permissions": {
      "cross-domain-content": ["*"]
  }

The script loads and runs, but in my browser console i'm getting:

XML Parsing Error: not well-formed
Location: 
Line Number 1, Column 1065:

in (unknown) - this being where the error occurs (the script name where the error occurs, is unknown basically) so i can't debug this - or better said, i have no idea how to.

What i believe is happening, is that somewhere on the call stack something gets misinterpreted by Firefox - and only in an extension environment.

Is there any way to load google adds (adsense ads) from a Firefox extension? Am i going about this the right way? Any help or idea is greatly appreciated!

Upvotes: 2

Views: 100

Answers (0)

Related Questions