Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for specific javascript variable value in Chrome Developer Tools

Just to give a background, editing a canned solution for a shopping cart provided by our POS system. There is no "remove" button and you must enter "0" and update to remove an item from the cart. I want a remove button, however this isn't on their priority list.

Trying to step through the spaghetti (utilizes DevExpress, as well, so a lot of jumping) but can't seem to find the place where it sends the qty value in the text box to update the cart. Basically, I want to put '15' (or something) into the qty update box and look where that variable is captured so I can create a remove button by just sending that function '0' instead.

TL;DR Is there a way to break where variable is set to a specific value? For example, when a variable is set to '15'.

Thanks in advance.

like image 714
justiceorjustus Avatar asked Mar 01 '26 08:03

justiceorjustus


1 Answers

You can put a breakpoint that only executes when a certain condition is met. In the Sources tab, open the file that has the script you want to insert the break into and click the line you want to break when executed. Then right click it and select Edit Breakpoint. Enter an expression such as qty == 15, and the break will only occur in that condition.

I don't think this exactly what you want. It seems like you want to break at the exact point in time the value changes.

An alternative would be to replace qty property on its parent object with another property that notifies you when the value changes. So in the console you'd enter something like this:

// assume that order is an object that contains qty.
order._qty = order.qty;
delete order.qty;
Object.defineProperty(order, 'qty', {
  get: function() {
    return this._qty;
  },
  set: function(newValue) {
    this._qty = newValue;
    if (this._qty == 15) {
      console.trace();
    }
  },
  enumerable: true,
  configurable: true
});

The setter property will set the quantity to the appropriate amount, and if quantity equals the your desired amount, will call Chrome's console.trace() function so you can see exactly how and where it's getting set.

like image 105
Daniel Gimenez Avatar answered Mar 02 '26 21:03

Daniel Gimenez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!