How to Monetize Chrome Extension by Injecting Ads in the Browser?

Posted on Posted in adsense, chrome browser, chrome extension, javascript

The Permanent URL is: How to Monetize Chrome Extension by Injecting Ads in the Browser? (AMP Version)

Monetizing on Chrome Extension isn’t easy e.g. You can’t put Adsense or other web-pages Ads easily in the Chrome extension because most third party ads providers will not let you put ads on Chrome popups which are not a proper web page (adsense needs to match ads base on the current page content).

You could, however, easily put a text link/image (e.g. affiliate), but that is static (and won’t change). Chrome extensions will not allow external scripts in the main popup html so the only way to display ads via Chrome Extension is to inject ads in the browser.

How to Inject Ads in the browser via Chrome Extension?

The first step is to add the following into the manifest.json of your chrome extension:

"content_scripts": [ { 
 "matches" : [ 
   "http://*/*", "https://*/*" 
 "js" : [ "js/ads.js" ], 
 "run_at" : "document_idle", 
 "all_frames" : false 

Above assumes that you put the ads.js code in the folder js. Next, the content of js/ads.js is:

  var s = document.createElement('script'); 
  s.src = '//';  // the third party external JS ads code.

It works by executing the Javascript code on document_idle (which is between document_end and document_start), then the Javascript code loads/injects the third party ads code in the current page.

However, I’d like to mention that: as it injects ads code in the browsers, which is bad for user’s experience. Especially that Popups are shown and very intrusive to users.