- ๐น 1. Start With the Browser Console (Most Important Step)
- ๐น 2. Confirm Your Script Actually Loaded
- ๐น 3. Check Command Registration Order
- ๐น 4. Check Your Metadata
- ๐น 5. Test Command Execution Directly in Console
- ๐น 6. Debug REST API Requests
- ๐น 7. Use Console Logging Inside Commands
- ๐น 8. Validate Command Arguments
- ๐น 9. Check for Other Plugins Overriding Your Command
- ๐น 10. Disable Browser Extensions That Inject Scripts
- ๐น 11. Test Add-On With All Other Plugins Disabled
- ๐น 12. Debug Infinite Loops or Freezing
- ๐ฏ Summary
- โ Check console for JS errors
- โ Ensure add-on JS loads correctly
- โ Register commands after terminal loads
- โ Validate and test metadata
- โ Log input arguments
- โ Test command function directly
- โ Debug REST responses via Network tab
- โ Check for syntax mistakes
- โ Remove naming conflicts
- โ Test in a clean environment
Learn how to diagnose problems in your JavaScript commands and REST API integrations.
If your custom command doesnโt work, prints errors, or behaves unpredictably, this guide walks you through the best debugging process.
Custom commands are pure JavaScript functions, and REST calls use WordPressโs JSON API, so debugging is straightforward once you know where to look.
๐น 1. Start With the Browser Console (Most Important Step) #
Open:
Right-click โ Inspect โ Console
Then run your custom command in the terminal.
Look for any JavaScript error:
Uncaught ReferenceError: mycommand is not defined
Uncaught TypeError: registry.mycmd is not a function
SyntaxError: Unexpected token
If you see any error:
- your add-on script likely failed
- commands wonโt register
- help wonโt show them
- terminal won’t run them
Fix the JS error first.
๐น 2. Confirm Your Script Actually Loaded #
Open:
Inspect โ Network โ JS
Look for your file:
my-addon.js
custom-commands.js
If the file is missing:
- Enqueue path is wrong
- File not uploaded
- CDN blocked it
- Plugin directory renamed
- Wrong file permissions
If the file is there but greyed out (blocked):
- caching plugin merged/minified it incorrectly
- script blocked by security plugin
Disable:
- JS minification
- Combine JS files
- Defer JS
- Rocket Loader (Cloudflare)
Reload and test again.
๐น 3. Check Command Registration Order #
Commands must be registered after the terminal loads.
Wrong:
registry.mycommand = ...
Correct:
window.addEventListener('load', function() {
CointactedSocialTerminalTerminal.registry.mycommand = function(input) {
append_line("OK", "system");
};
});
If you register too early โ registry is undefined.
๐น 4. Check Your Metadata #
For command to show in help, metadata must be valid.
Example:
CointactedSocialTerminalTerminal.commands_meta.mycommand = {
group: "ADDON",
description: "Says hello",
alias: ["hi"],
public: true
};
Missing keys can cause help issues.
Common errors:
โ group name missing
โ typo in key (e.g., descripton)
โ setting hidden: true
Fix metadata โ reload browser.
๐น 5. Test Command Execution Directly in Console #
Before typing in terminal, test the function in console:
CointactedSocialTerminalTerminal.registry.mycommand({
cmd: "mycommand",
args: [],
raw: "mycommand"
});
If this works โ your function is fine.
If this fails โ issue inside your code.
This isolates input parsing from your command logic.
๐น 6. Debug REST API Requests #
If your command uses fetch():
const res = await fetch('/wp-json/myaddon/v1/data');
Open:
Inspect โ Network โ Fetch/XHR
Click on your request:
Check for:
- Status code (200, 403, 404, 500)
- Response body
- JSON output
- CORS issues
- Nonce/Authentication issues
Common problems:
โ 404 #
Route not registered:
register_rest_route('myaddon/v1', '/data', [...]
โ 403 #
Permission callback blocked it:
Fix:
'permission_callback' => '__return_true'
(or proper permission logic)
โ 500 #
PHP error in callback.
Enable debug:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Then check:
/wp-content/debug.log
๐น 7. Use Console Logging Inside Commands #
Example:
registry.mycmd = function(input) {
console.log("Input:", input);
console.log("Args:", input.args);
console.log("Raw:", input.raw);
append_line("OK", "system");
};
This helps with:
- argument parsing
- alias handling
- debugging incorrect user syntax
๐น 8. Validate Command Arguments #
User may type something your command doesnโt expect.
Example:
random a b
Add validation:
if (input.args.length < 2) {
return append_line("Usage: random min max", "error");
}
Validate:
- number arguments
- URL formats
- required fields
- JSON structure
๐น 9. Check for Other Plugins Overriding Your Command #
If another plugin uses the same command name:
registry.status
Your command will be overwritten.
Check:
help search status
If the description doesnโt match your metadata โ you have a naming conflict.
Fix:
- rename your command
- use namespacing:
myaddon_status
๐น 10. Disable Browser Extensions That Inject Scripts #
Extensions like:
- Grammarly
- LanguageTool
- Password managers
- Privacy blockers
- Web3 blockers
โฆinject scripts into input fields and can break terminal behavior.
Test in:
- Chrome Incognito
- Firefox Private Window
If command works there โ an extension is interfering.
๐น 11. Test Add-On With All Other Plugins Disabled #
To isolate the environment:
- Deactivate all plugins except:
- Cointacted Social Terminal
- Your add-on
- Switch to default theme
- Test command again
If it works:
Another plugin or theme is breaking scripts.
If it still doesnโt work:
Your command contains a logic or syntax error.
๐น 12. Debug Infinite Loops or Freezing #
If command freezes:
while(true) {}
or heavy loops without async:
for (let i=0; i<1e9; i++) {}
Use async functions to break work into chunks:
await new Promise(r => setTimeout(r));
Never block the main thread.
๐ฏ Summary #
To debug custom commands:
โ Check console for JS errors #
โ Ensure add-on JS loads correctly #
โ Register commands after terminal loads #
โ Validate and test metadata #
โ Log input arguments #
โ Test command function directly #
โ Debug REST responses via Network tab #
โ Check for syntax mistakes #
โ Remove naming conflicts #
โ Test in a clean environment #
Following these steps resolves almost every custom command issue.