Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break when style has changed in Chrome Dev Tools

I just wonder if anyone know if it's possible to add a break point on a specific css property on a specific element in Chrome Dev Tools, i.e when #mydiv's height property has changed, break.

like image 240
bjorkblom Avatar asked Nov 09 '12 07:11

bjorkblom


People also ask

How do I add a conditional breakpoint in Chrome?

Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression. Note: Because the conditional breakpoint simply evaluates an expression, you can add useful logging statements within the expression.

How do I save CSS changes of styles panel of Chrome developer tools?

To save your changes, press CTRL + S when editing the file.


2 Answers

You can only break on all inline style (<div style="height: 20px; width: 100%">) changes using the Elements panel context menu's Break on... | Attributes modifications.

like image 103
Alexander Pavlov Avatar answered Oct 19 '22 08:10

Alexander Pavlov


You can do it this way:

function observe(el, property) {
    var MutationObserver = window.WebKitMutationObserver;

    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            console.log('old', mutation.oldValue, 'new', mutation.target.style.cssText, 'mutation', mutation);
            if (mutation.attributeName == property) debugger;
        });
    }
    );

    var config = {
        attributes: true,
        attributeOldValue: true
    }

    observer.observe(el, config);
}

Then you can set breakpoint on style change like this: observe(element, "style")

It will break when it changes and also print in console old and new value.

like image 39
elixon Avatar answered Oct 19 '22 10:10

elixon