Insert AdSense ad to website using Chrome Extension content script

I’m trying to insert AdSense ad to website using Chrome Extension’s content script. My code looks like this:

> var div = document.getElementById('myDiv');
> div.innerHTML = '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-*************" data-ad-slot="*********" data-ad-format="auto"></ins> <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>';

But it shows no ads. Of course, I set manifest file’s “matches” field correctly, I have experience with content scripts, but never worked with AdSense.

And yes, I know Google is not affirmative with this way of inserting ads, but I do this for an friend who thinks it is OK, so I don’t care, I just wish to show his ads in that div.

Thanks

How are you calling the code within your HTML?

Actually i try to insert AdSense ads into all facebook pages. So I get an div with getElementById(that element’s id), and try with changing it’s innerHTML. I can change it’s HTML to show text, i.e. writing div.innerHTML = “random text” outputs random text inside of it, but when I try to show an adsense ad instead of that simple text, nothing happens.

Can I just check, are you interested in inserting ads into your own website, or a Facebook page?

All facebook pages.

Looks like it can’t be done.

https://productforums.google.com/forum/?hl=en#!category-topic/adsense/i-have-an-active-account-working-with-adsense/BUOYmkYUO90

I don’t care if Google bans his account, so Google terms are not my problem.
I just want the ads to be shown inside an facebook’s div, that’s it…

My point was that I do not believe there is a way to do what you want.

But we do not encourage members to break the ToS of other sites, so you are unlikely to find further help here.

1 Like

can you tell me how facebook blocks this? which mechanism they use? as when I try this code on my local website it works…

Which part of

made you think you were going to get an answer to that?

1 Like

We are not Facebook, you should ask them.

1 Like

Not that they would tell you.

Anyway there’s little point in using a browser extension for inserting ads into pages as the only person who will see them if you ever did get it to work would be you.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.