TIL adding a debug flag for custom features
POSTED ON:
TAGS: debug url-parameters
This is a cool way to turn on some debug tricks.
Adding ?debug
flag to turn on a bunch of config options.
// website.com/?color=blue&debug=true
const urlParams = new URLSearchParams(window.location.search);
const pageType = urlParams.get('color')
const isDebug = urlParams.get('debug')
console.log(pageType); // blue
console.log(isDebug); // true
Then in your JS, you can:
- Turns on outlines, to check for any layout issues.
- Turns on Lighthouse
- Turn on console.logs. So hide them with a debug flag.
- Run specific tests.
You probably don't want to pass this code to production though.
And maybe it might be better to use (.env)[https://www.npmjs.com/package/dotenv].
Related TILs
Tagged: debug