npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@codepenguin/adsense-simulator

v3.0.0

Published

A lightweight development simulator for Google AdSense that mimics ad slot behavior locally.

Downloads

230

Readme

@codepenguin/adsense-simulator

A lightweight development tool that simulates Google AdSense behavior locally.

This allows developers to test ad placements, responsive layouts, and integration logic without loading real Google ads.

The simulator reproduces key runtime behaviors of AdSense while running entirely in the browser with no external network requests.

⚠️ Development use only. Do not use in production.


Features

The simulator reproduces important behaviors of Google AdSense:

  • .adsbygoogle slot detection
  • adsbygoogle.push() queue handling
  • responsive ad sizing
  • container-based ad selection
  • dynamic DOM insertion detection
  • SPA navigation support
  • back/forward navigation handling
  • bfcache (back-forward cache) support
  • click simulation
  • ad metadata inspection
  • optional blocking of the real AdSense script

Installation

npm

npm install @codepenguin/adsense-simulator

Then import it in your development environment:

import "@codepenguin/adsense-simulator";

CDN

You can also use the simulator directly in static HTML pages.

<script src="https://cdn.jsdelivr.net/npm/@codepenguin/adsense-simulator/dist/adsense-simulator.min.js"></script>

Example Ad Slot

Use normal AdSense markup.

<ins
  class="adsbygoogle"
  style="display:block;width:300px;height:250px"
  data-ad-client="ca-pub-demo"
  data-ad-slot="123456"
>
</ins>

<script>
  (adsbygoogle = window.adsbygoogle || []).push({});
</script>

The simulator will render a mock ad displaying useful debug information.

Example:

adsense-simulator
client: ca-pub-demo
slot: 123456
size: 300x250
format: fixed

Responsive Ads

Responsive slots are supported.

<ins
  class="adsbygoogle"
  style="display:block"
  data-ad-client="ca-pub-demo"
  data-ad-slot="123456"
  data-ad-format="auto"
>
</ins>

The simulator chooses an appropriate ad size based on container width.


Dynamic Ads (SPA / React / Astro)

The simulator automatically detects dynamically inserted ads.

const ad = document.createElement("ins");

ad.className = "adsbygoogle";
ad.style.display = "block";
ad.style.width = "300px";
ad.style.height = "250px";

ad.setAttribute("data-ad-client", "ca-pub-demo");
ad.setAttribute("data-ad-slot", "123456");

document.body.appendChild(ad);

adsbygoogle.push({});

MutationObserver automatically triggers a scan.


Click Simulation

Clicking a simulated ad opens a mock advertiser page displaying ad metadata.

Example data shown:

  • client
  • slot
  • ad size
  • format
  • container width
  • page path
  • timestamp

This helps verify correct ad configuration.


Blocking Real AdSense Script

During development you may want to prevent the real AdSense script from loading to avoid conflicts with the simulator.

Use the data-remove-google-ads attribute on the script tag:

<script
  src="https://cdn.jsdelivr.net/npm/@codepenguin/adsense-simulator/dist/adsense-simulator.min.js"
  data-remove-google-ads="true"
></script>

When enabled, the simulator intercepts attempts to load:

https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js

and prevents it from downloading.

⚠️ Note: Query string parameters (e.g. ?removeGoogleAds=true) do not work when loading from jsDelivr or unpkg — CDNs strip query strings before serving files. Always use the data-remove-google-ads="true" attribute instead.


Console Output

When the simulator starts you will see:

adsense-simulator: started { removeGoogleAds: "true" }

If the real AdSense script is blocked:

adsense-simulator: blocked Google AdSense script

Supported Ad Sizes

The simulator supports common AdSense sizes including:

  • 320×50
  • 468×60
  • 728×90
  • 300×250
  • 336×280
  • 160×600
  • 300×600
  • 970×90
  • 970×250

Responsive ads automatically choose the closest match.


Runtime Behavior

The simulator processes ads using a queue system similar to AdSense:

adsbygoogle.push()
        ↓
queue intercept
        ↓
slot scanning
        ↓
ad rendering

Dynamic content and SPA navigation are handled via MutationObserver.


Known Limitations

Blocking real AdSense is best-effort

The data-remove-google-ads blocker uses a MutationObserver to detect and remove AdSense script tags. Because MutationObserver fires asynchronously (after the current JS task), there is a small window where the browser may have already started fetching the script before removal.

For guaranteed blocking in a dev environment, add a Content Security Policy to your dev server:

Content-Security-Policy: script-src 'self' 'unsafe-inline'

This prevents the AdSense script from loading at the network level regardless of how it is injected.


What This Simulator Does NOT Replicate

This tool does not simulate Google's ad network infrastructure.

It does not provide:

  • real ads
  • advertiser targeting
  • auctions
  • revenue tracking
  • fraud detection
  • AdSense account validation

Those systems run exclusively on Google's servers.


License

MIT


Repository

https://github.com/clowneon1/adsense-simulator