What Are Userscripts?
Userscripts are JavaScript programs that run automatically on specific websites. They can:- Modify how websites look (themes, layouts, fonts)
- Add new features (buttons, shortcuts, tools)
- Remove unwanted elements (ads, popups, banners)
- Automate repetitive tasks (form filling, data extraction)
- Expose website functionality to AI agents (WebMCP servers)
All userscripts run locally in your browser. They only affect your view of websites - not other users’.
Accessing the Userscript Manager
Creating Userscripts
Using an AI Agent
The easiest way to create userscripts is by asking an AI agent:- Userscript Engineer
- WebMCP Server
Describe what you want
“Add a dark mode toggle to reddit.com” or “Remove ads from news.ycombinator.com”
Manual Creation
For advanced users, you can write userscripts manually:Downloading Userscripts
Export Individual Scripts
Export All Scripts
Uploading Userscripts
Import Individual Scripts
Import Script Library
Using Userscripts
Enable/Disable Scripts
- Individual Scripts
- All Scripts
Toggle the switch next to each script to enable or disable it. Changes take effect immediately on matching pages.
Reload After Changes
When you modify or enable a userscript:Updating Scripts
- Via Agent
- Manual Edit
Open a chat, mention the script name, and describe the changes you want. The agent will update the script for you.
Organizing Scripts
Naming Convention
Use clear, descriptive names:Good Names
github-dark-modereddit-hide-sidebaramazon-price-tracker
Avoid
script1testuntitled
URL Patterns
Configure which sites each script runs on:Categories
Group related scripts for easy management:- Productivity: Auto-fill forms, keyboard shortcuts
- Appearance: Dark modes, custom themes, layout changes
- Content: Ad blockers, element hiders
- Automation: Data extraction, monitoring
- MCP Servers: Scripts that expose website tools to AI
Sharing Userscripts
Export for Sharing
Publish to Community
Share your best scripts with the community:GitHub Gist
Post your script as a Gist for easy sharing
Discord
Share in the WebMCP Discord #userscripts channel
Examples Repo
Submit a PR to the official examples repository
Social Media
Tweet about your creation with #WebMCP
Installation Instructions for Others
When sharing a script, include these steps:Troubleshooting
Script not running
Script not running
Possible causes:
- Script is disabled (check the toggle)
- URL pattern doesn’t match current page
- Page needs to be refreshed
- Script has JavaScript errors
Script conflicts with website
Script conflicts with website
Possible causes:
- Script selectors clash with site’s JavaScript
- Script modifies elements the site depends on
- Multiple scripts affecting the same elements
Import fails
Import fails
Possible causes:
- File format not recognized
- Malformed JSON in backup file
- Script has syntax errors
.ts, .js, .user.js, or .json). For JSON backups, validate the JSON structure. For scripts, check for syntax errors.Script works then stops working
Script works then stops working
Possible causes:
- Website updated and changed their HTML structure
- Selectors no longer match elements
- Website added anti-automation measures
Performance issues
Performance issues
Possible causes:
- Too many scripts running simultaneously
- Script has infinite loops or memory leaks
- Script runs on too many sites
Best Practices
Test in Private Window
Test scripts in incognito/private mode to ensure they work without other extensions interfering
Use Version Control
Export scripts regularly and keep versions so you can roll back if needed
Comment Your Code
Add comments explaining what each section does for future reference
Start Small
Build simple scripts first, then add complexity as needed
Use Stable Selectors
Target elements by ID or data attributes rather than generated class names
Handle Errors Gracefully
Add checks for missing elements and provide fallback behavior
Advanced Features
Script Execution Timing
Control when your script runs:- document_start
- document_end
- document_idle
Runs as soon as possible, before page loads. Good for blocking content or modifying page behavior early.
Script World
Choose where the script executes:- MAIN
- ISOLATED
Runs in the page’s context with full access to page JavaScript. Required for MCP servers.
Using Web Standard APIs
WebMCP servers use the W3C Web Model Context API (navigator.modelContext) - global helpers and Zod are available:
Zod Support: The web standard API accepts Zod schemas (preferred) as well as traditional JSON Schema. Zod provides better TypeScript integration, validation, and developer experience.
Security Considerations
Only install trusted scripts
Only install trusted scripts
Review code before importing scripts from others. Malicious scripts can steal passwords, track activity, or perform unwanted actions.
Limit URL patterns
Limit URL patterns
Don’t use
<all_urls> unless absolutely necessary. Restrict scripts to specific domains they need.Avoid storing sensitive data
Avoid storing sensitive data
Don’t hardcode passwords, API keys, or personal information in scripts. Use browser storage APIs with caution.
Keep scripts updated
Keep scripts updated
Regularly review and update scripts to ensure they still work correctly and securely.
Use HTTPS
Use HTTPS
Only run scripts on HTTPS sites when possible to prevent man-in-the-middle attacks.
Examples and Templates
Examples Repository
Browse tested userscript examples for common tasks
WebMCP Playground
See WebMCP servers in action on a demo site
Discord Community
Get help and share scripts with other users
Extension Tools API
Technical reference for userscript management APIs
Quick Reference
Common Tasks
- Create
- Enable/Disable
- Edit
- Download
- Upload
- Delete
Ask Userscript Engineer or WebMCP Server agent → Describe what you want → Agent builds and tests → Script is saved
Next Steps
Try creating a simple script
Ask the Userscript Engineer to add a dark mode to your favorite website
Learn about agents
Read the Understanding Agents guide to choose the right agent for each task
Explore examples
Check out the Examples Repository for inspiration
Join the community
Share your creations on Discord
