The most annoying Chrome Extension

The hardest part of any new project is just getting started. Whenever a task seems overwhelming the best way forward is to break it into smaller tasks. For programming tasks that means getting started with basic bootstrapping activities, and since they’re the same for every project, they can be pretty easily templated.

With that in mind I wrote this step by step guide to create the most annoying Chrome Extension ever. On roughly half of the pages you load it pops up an image overlay with a close button. You can use whatever image file you have, but I used this SpongeBob image

Use it to quickly get a Chrome Extension project up and running. Once that’s done, you can begin customizing the project to do whatever you want.

  1. Create a project folder directory on your local file system
  2. Add the following sub directories
    • images
    • scripts
  3. Under the top project directory create the following file
    • manifest.json
  4. Under the scripts directory create the following file
    • content.js

Copy this text to manifest.json

    "name": "Project Name",
    "version": "1.0",
    "description": "Your description here",
        "16": "images/icon-16.png",
        "32": "images/icon-32.png",
        "48": "images/icon-48.png",
        "128": "images/icon-128.png"
            "resources":["/images/*.png", "/images/*.jpg"],

Copy this text to content.js

var myz_index = 12000;
let randNum = Math.floor(Math.random() * 10);
imgSrc = chrome.runtime.getURL("images/spongebob.jpg")

window.addEventListener('load', function(){
    if(randNum > 4)
        overDiv(imgSrc, 2);

function overDiv(imgSrc, category){
    var overlay = document.createElment('div'); = "ahOverlay"; = 'fixed'; = '0px'; = '0px';
    overlay.filter = "blur(10px)"; = window.innerWidth; = '100%'; = '100%'; = window.innerHeight; = 'rgb(255,255,255,0.9)'; = myz_index; 
    body = document.getElementByTagName('body');
    var closeButton = document.createElement('button'); = "ahCloseButton";
    var getWidth = overlay.clientWidth/2;
    closeButton.setAttribute('style':'left:'+getWidth+'px !important');
    var closeButtonPos = getWidth + 'px';
    closeButton.value = 'Close';
    closeButton.zIndex = myx_index + 1;
    closeButton.backgroundColor = 'green';
    closeButton.setAttribute("style", "background-color:green !important; color: white; padding: 8px; font-size: 1.3rem; margin-left:"+getWidth+"px; margin-top: 50px;");
    closeButton.textContent = 'Close';

    var br = document.createElement("br");

    var ahad = document.createElement("img")"ahad";
    margins = getWidth/2;
    ahad.setAttribute("style", "width:"+getWidth+"px;margin-left:"+margins+"px;");
    ahad.minWidth = '80%';
    ahad.src = imgSrc; 
  • Make sure Developer mode is turned on in Chrome (Settings -> Extenstions -> Manage Exstensions -> Developer Mode
  • Load the extension by clicking the Load Unpacked button at the top of the Manage Extensions screen and selecting your project’s root directory.