We've all been there. You need to test a feature, mock a UI change, or repeatedly populate a form with test data on a staging site. The traditional path is to spin up a local build, mock an API, or worse, manually click over and over.
There's a faster way: Tampermonkey.
Most devs know it as a userscript manager for customizing websites, but it's an incredible tool for our own workflow. Think of it as a browser-based, domain-specific REPL for the DOM.
Why it's a Dev Power-Up:
- Instant Staging/Prod UI Tweaks: Need to see how a button looks in a different color on the live site? Write a 3-line script to change it. No deployments, no branches.
- Automate Repetitive QA Tasks: Automatically log in with test credentials, fill out complex forms, or navigate to a specific deep-linked state every time you load the page.
- Inject Mock Data: Use
GM_xmlhttpRequest
to intercept calls and return mock JSON, or directly inject a data payload into the UI to test rendering without a backend. - Add Debugging Panels: Build a custom floating debug panel that shows internal application state that the UI doesn't normally expose.
A Simple Example: Auto-Login for Staging
Instead of fetching the password from your password manager every time, a simple script can do it for you.
// ==UserScript==
// @name Staging Auto-Login
// @match https://staging.yourcompany.com/login
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Wait for the form to load
setTimeout(() => {
document.querySelector('#email').value = 'test@yourcompany.com';
document.querySelector('#password').value = 'test-password-123';
document.querySelector('button[type="submit"]').click();
}, 1000);
})();
It's not about being lazy; it's about removing friction from your development loop.
If you're curious about more advanced uses, like managing a whole library of dev scripts or using modern JS tooling with Tampermonkey, this guide on how to turn your browser into a cheat code is a great next step.
What's your go-to Tampermonkey script for boosting your dev productivity?
Top comments (0)