I have an issue in a production environment that I'm trying to debug. I can't place in debugger or console.log statements since the issue is happening only in a production environment. I can view the prettified code in Chrome.
When I look at the source code, it looks like this:
functionWhatever = function (text, copy) {
var range;
if (document.selection) {
range = document.body.createTextRange();
range.moveToElementText(clipboardtext);
range.select();
} else if (window.getSelection) {
range = document.createRange();
range.selectNodeContents(clipboardtext);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
...
},
But in Chrome's development tools, the prettified code looks like this:
u = function(e, t) {
var n;
document.selection ? (n = document.body.createTextRange(),
n.moveToElementText(e),
n.select()) : window.getSelection && (n = document.createRange(),
n.selectNodeContents(e),
window.getSelection().removeAllRanges(),
window.getSelection().addRange(n)),
...
},
I am not able to set a breakpoint on one of the lines that end in a comma in the minimized code. How can I (or is there a way to) debug one of those lines?
There is a way to do it natively within Chrome Development tools. You can step-in step-out for each part of the chain of functions. For example, if you have
a(), b(), c()
and you want to debug the c() call, you can
and then the debugger will be at the state just before the call to c() (It may skip assignments or things that aren't functions.)
So for the above example, you just put a breakpoint on the var n; line, then start performing step-in, step-out to get you to the point of the code you want to debug, then use the console to debug the statements you want to inspect.
You can use Requestly extension to debug your JS files in your production environment.
This will make sure that your file is picked by the browser instead of the production environment. Now you can make changes to the file uploaded in Requestly (debug point, console log) and it all will be picked up by the browser.
As mentioned in the comment by OP, If you don't want to upload your code on Requestly Mock Server, you can simple run a local server and just set up a Redirect Rule in Requestly like this
URL Equals/Contains <your_production_JS_URL>
Redirect to <your_localserver_JS_URL>
Happy debugging!!
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