Building Kale: An Ethical Open-Source Alternative to Affiliate Hijacking

Overview

Modern browser extensions often use aggressive monetization tactics that undermine the very creators they sponsor.

notoriously overrides existing affiliate cookies, redirecting commissions from independent creators to itself. This guide explores the architecture of Kale, an ethical alternative designed to prioritize creator income while still providing consumer value through automated coupon application.

Prerequisites

To follow this implementation, you should understand:

  • JavaScript (ES6+): For extension logic and DOM manipulation.
  • Browser APIs: Specifically chrome.runtime and chrome.cookies.
  • Python: For backend scraping and API management.
  • Web Architecture: Understanding how cookies and HTTP redirects function.

Key Libraries & Tools

  • Chrome Extension API: The core framework for browser interaction.
  • Beautiful Soup: A
    Python
    library for scraping coupons from external sites.
  • Cloud Functions: Serverless components to handle periodic data scraping.
Building Kale: An Ethical Open-Source Alternative to Affiliate Hijacking
I Built a Version of Honey That Actually SUPPORTS Creators

Code Walkthrough

The Manifest Foundation

The manifest.json file defines the extension's boundaries. You must explicitly request permissions to interact with sensitive user data.

{
  "manifest_version": 3,
  "permissions": ["storage", "tabs", "cookies", "activeTab"],
  "host_permissions": ["https://*/*"]
} 

Protecting Creator Commissions

The core of the "not-evil" philosophy is the isAffiliated function. It checks for existing cookies before the extension attempts to inject its own, preventing commission theft.

async function isAffiliated(domain, cookieName) {
  const cookies = await chrome.cookies.getAll({ domain });
  const found = cookies.filter(c => c.name === cookieName);
  return found.length > 0;
}

Backend Automation

For the backend, we use

to gather current discount codes. This ensures the extension database remains fresh without manual entry.

import requests
from bs4 import BeautifulSoup

def scrape_coupons(url):
    res = requests.get(url)
    soup = BeautifulSoup(res.text, 'html.parser')
    # Logic to extract code strings
    return [tag.text for tag in soup.find_all(class_='coupon-code')]

Syntax Notes

Browser extensions rely heavily on asynchronous patterns. Use async/await when calling chrome.cookies or chrome.tabs to avoid blocking the main UI thread. In the Python scraping logic, CSS selectors provide the most reliable way to target specific coupon containers on diverse e-commerce layouts.

Practical Examples

If a user visits

, Kale scans for an existing affiliate cookie. If absent, the extension displays a popup offering two choices: apply a coupon to support the Kale developers or apply one that randomly credits a creator like
MrBeast
or
PewDiePie
.

Tips & Gotchas

  • Cross-Browser Compatibility: Chrome and Firefox use different API namespaces (chrome vs browser). Use a polyfill to maintain a single codebase.
  • DOM Injection: Websites frequently change their checkout page IDs. Implement robust error handling in content.js to ensure the popup doesn't break the user's checkout flow.
3 min read