8.1 KiB
Build Instructions
This document contains detailed instructions for building and distributing the Greasemonkey browser extension.
Prerequisites
- Web browser (Chrome or Firefox)
- Text editor (for development)
- Node.js and npm (optional, for Firefox automated builds)
Quick Start
Testing Locally
Chrome
1. Open Chrome
2. Navigate to chrome://extensions/
3. Enable "Developer mode" (top-right toggle)
4. Click "Load unpacked"
5. Select the greasemonkey/chrome directory
Firefox
1. Open Firefox
2. Navigate to about:debugging#/runtime/this-firefox
3. Click "Load Temporary Add-on"
4. Select greasemonkey/firefox/manifest.json
Development Workflow
1. Making Changes
Edit files in the appropriate directory (chrome/ or firefox/).
Key files:
manifest.json- Extension configurationpopup.html- UI structurepopup.css- UI stylingpopup.js- UI functionalitycontent.js- Code that runs on web pagesbackground.js- Background service/script
2. Testing Changes
After making changes:
Chrome:
- Go to
chrome://extensions/ - Click the reload icon on the Greasemonkey extension card
- Test your changes
Firefox:
- Go to
about:debugging#/runtime/this-firefox - Click "Reload" on the Greasemonkey extension
- Test your changes
3. Debugging
Chrome:
- Background script logs:
chrome://extensions/→ "service worker" link - Content script logs: Browser console on any page (F12)
- Popup logs: Right-click popup → "Inspect"
Firefox:
- Background script logs:
about:debugging→ "Inspect" on extension - Content script logs: Browser console on any page (F12)
- Popup logs: Right-click popup → "Inspect Element"
Building for Distribution
Chrome/Edge Build
Method 1: Manual Packaging (Recommended for Testing)
- Open Chrome
- Go to
chrome://extensions/ - Ensure "Developer mode" is enabled
- Click "Pack extension"
- For "Extension root directory", select the
chromefolder - Leave "Private key file" empty for first build
- Click "Pack Extension"
- Chrome generates two files:
chrome.crx- The packaged extensionchrome.pem- Private key (keep this secure for updates!)
Method 2: Chrome Web Store Distribution
- Create a developer account at Chrome Web Store
- Pay one-time $5 registration fee
- Create a ZIP file of the
chromedirectory:cd chrome zip -r ../greasemonkey-chrome.zip * - Upload to Chrome Web Store dashboard
- Fill in store listing details
- Submit for review
Note: Keep your .pem private key file secure. You'll need it for future updates.
Firefox Build
Method 1: Temporary Installation (Development)
Already covered in Quick Start - good for testing only. Temporary add-ons are removed when Firefox restarts.
Method 2: Self-Distribution (Unverified)
- Create a ZIP file:
cd firefox zip -r ../greasemonkey-firefox.zip * - Rename to
.xpi:mv greasemonkey-firefox.zip greasemonkey-firefox.xpi - Users can install by dragging
.xpifile to Firefox - Firefox will show "unverified" warning
Method 3: Official Distribution (Recommended)
-
Install web-ext tool:
npm install -g web-ext -
Build the extension:
cd firefox web-ext buildThis creates a ZIP file in
web-ext-artifacts/directory -
Sign with Mozilla:
- Create account at addons.mozilla.org
- Get API keys from Developer Hub
- Sign the extension:
web-ext sign \ --api-key=YOUR_API_KEY \ --api-secret=YOUR_API_SECRET - Or upload manually to addons.mozilla.org
-
Distribution options:
- Listed: Public on addons.mozilla.org (requires review)
- Unlisted: Self-distribute signed XPI (automatic signing)
Directory Structure
greasemonkey/
├── chrome/ # Chrome extension
│ ├── manifest.json
│ ├── background.js
│ ├── content.js
│ ├── popup.html
│ ├── popup.css
│ ├── popup.js
│ ├── icon16.png
│ ├── icon48.png
│ └── icon128.png
├── firefox/ # Firefox extension
│ ├── manifest.json
│ ├── background.js
│ ├── content.js
│ ├── popup.html
│ ├── popup.css
│ ├── popup.js
│ ├── icon16.png
│ ├── icon48.png
│ └── icon128.png
├── README.md
└── BUILD.md # This file
Version Updates
When releasing a new version:
-
Update version number in both
manifest.jsonfiles:"version": "1.1.0" -
Update README.md version history
-
Test thoroughly in both browsers
-
Build new packages:
- Chrome: Re-pack with same
.pemkey - Firefox: Build and sign new version
- Chrome: Re-pack with same
-
Upload to respective stores/distribution channels
Quality Checklist
Before building for distribution:
- Test all features in Chrome
- Test all features in Firefox
- Verify icons display correctly
- Check manifest.json versions match
- Test storage sync functionality
- Verify permissions are appropriate
- Test on various websites
- Check browser console for errors
- Test add/edit/delete rule functionality
- Verify enable/disable toggles work
- Test all match types (URL, Element, Both)
- Review code for security issues
- Update version numbers
- Update documentation
File Size Optimization
To reduce extension size:
-
Minify JavaScript (optional):
npm install -g terser terser popup.js -c -m -o popup.min.js -
Optimize PNG icons:
# If you have optipng installed optipng icon*.png -
Remove development files:
- Source maps
- Test files
- Documentation (keep only in repo)
Automated Build Script
You can create a build script for automation:
#!/bin/bash
# build.sh
VERSION="1.0.0"
echo "Building Greasemonkey v${VERSION}..."
# Chrome build
echo "Building Chrome extension..."
cd chrome
zip -r "../dist/greasemonkey-chrome-${VERSION}.zip" * -x "*.DS_Store"
cd ..
# Firefox build
echo "Building Firefox extension..."
cd firefox
zip -r "../dist/greasemonkey-firefox-${VERSION}.zip" * -x "*.DS_Store"
cd ..
echo "Build complete! Files in dist/ directory"
Make it executable:
chmod +x build.sh
mkdir -p dist
./build.sh
Common Issues
Chrome Extension Doesn't Load
- Check manifest.json syntax (use JSON validator)
- Ensure all referenced files exist
- Check browser console for errors
Firefox Temporary Add-on Removed
- This is expected behavior
- Use web-ext for persistent testing:
cd firefox web-ext run
Icons Not Showing
- Verify icon files exist
- Check file paths in manifest.json
- Ensure icon sizes are correct (16x16, 48x48, 128x128)
Storage Not Persisting
- Chrome: Check sync is enabled in browser
- Firefox: Temporary add-ons don't persist storage
- Use proper signed/installed extension for testing
Distribution Platforms
Official Stores
Self-Distribution
- GitHub Releases
- Personal website
- Direct XPI/CRX files
Security Notes
- Never commit your Chrome
.pemprivate key - Keep Firefox API keys secure
- Don't bundle sensitive data in extension
- Review all code before distribution
- Test on malicious sites carefully
Resources
- Chrome Extension Documentation
- Firefox Extension Documentation
- web-ext Documentation
- Bootstrap Documentation
Support
For build issues or questions, contact Andy Dixon.