What's the best way to debug custom User Scripts (aka Greasemonkey) in Chrome? Is there a way to enable User Script tracking in the Developer Tools?
What kind of debugging do you want? Like Alex said, user scripts will be listed in the same context as debugging the page itself. If you go to the "scripts" tab in the developer tools, you'll see a bar with a dropdown which will allow you to select the appropriate javascript file you wish to debug. Such scripts should have urls that look like chrome-extension://<hash>/<script file>.js
. Those scripts will also log to the console of the page they're embedded on.
Additionally, if you want to log in the same place for all pages, you can try building your script as a full chrome extension, using the user script as a content script. Then you can send a message from your content script to your background page and log there. For example, if this were your content script:
function log(text) {
chrome.extension.sendRequest({'action' : 'log', 'text' : text}, function() {});
};
log("Content script loaded: " + window.location.href);
And this were your background page:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function onRequest(request, sender, callback) {
if (request.action && request.action == 'log') {
console.log(request.text);
}
};
chrome.extension.onRequest.addListener(onRequest);
</script>
</body>
</html>
You would see each load of the content script in the background page's log.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With