<commit_before>using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using Tellurium.MvcPages.SeleniumUtils;

namespace Tellurium.MvcPages.WebPages
{
    public class PageFragmentWatcher
    {
        private readonly RemoteWebDriver driver;
        private readonly IWebElement element;
        private readonly string watcherId;
        
        public PageFragmentWatcher(RemoteWebDriver driver, IWebElement element)
        {
            this.driver = driver;
            this.element = element;
            this.watcherId = Guid.NewGuid().ToString();
        }

        public void StartWatching(bool watchSubtree=true)
        {
            driver.ExecuteScript(@"
(function(target, watcherId, watchSubtree){
        var launchTicket = null;
        window.__selenium_observers__ =  window.__selenium_observers__ || {};
        window.__selenium_observers__[watcherId] = {
                observer: new MutationObserver(function() {
                        clearTimeout(launchTicket);
                        launchTicket = setTimeout(function(){
                            window.__selenium_observers__[watcherId].occured = true;
                            window.__selenium_observers__[watcherId].observer.disconnect();
                        }, 250);
                }),
                occured:false
        };
        var config = { attributes: true, childList: true, characterData: true, subtree: watchSubtree };
        window.__selenium_observers__[watcherId].observer.observe(target, config);
})(arguments[0],arguments[1], arguments[2]);", element, watcherId, watchSubtree);
        }

        public void WaitForChange(int timeout = 30)
        {
            try
            {
                driver.WaitUntil(timeout,
                    d =>
                        (bool)
                        driver.ExecuteScript(
                            "return window.__selenium_observers__ && window.__selenium_observers__[arguments[0]].occured;",
                            watcherId));
            }
            catch (WebDriverTimeoutException ex)
            {
                throw new CannotObserveAnyChanges(element, ex);
            }
            
        }
    }

    public class CannotObserveAnyChanges:ApplicationException
    {<commit_msg>Revert unintended changes<commit_after>using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using Tellurium.MvcPages.SeleniumUtils;

namespace Tellurium.MvcPages.WebPages
{
    public class PageFragmentWatcher
    {
        private readonly RemoteWebDriver driver;
        private readonly IWebElement element;
        private readonly string watcherId;
        
        public PageFragmentWatcher(RemoteWebDriver driver, IWebElement element)
        {
            this.driver = driver;
            this.element = element;
            this.watcherId = Guid.NewGuid().ToString();
        }

        public void StartWatching(bool watchSubtree=true)
        {
            driver.ExecuteScript(@"
(function(target, watcherId, watchSubtree){
        window.__selenium_observers__ =  window.__selenium_observers__ || {};
        window.__selenium_observers__[watcherId] = {
                observer: new MutationObserver(function(mutations) {
                        window.__selenium_observers__[watcherId].occured = true;
                        window.__selenium_observers__[watcherId].observer.disconnect();
                }),
                occured:false
        };
        var config = { attributes: true, childList: true, characterData: true, subtree: watchSubtree };
        window.__selenium_observers__[watcherId].observer.observe(target, config);
})(arguments[0],arguments[1], arguments[2]);", element, watcherId, watchSubtree);
        }

        public void WaitForChange(int timeout = 30)
        {
            try
            {
                driver.WaitUntil(timeout,
                    d =>
                        (bool)
                        driver.ExecuteScript(
                            "return window.__selenium_observers__ && window.__selenium_observers__[arguments[0]].occured;",
                            watcherId));
            }
            catch (WebDriverTimeoutException ex)
            {
                throw new CannotObserveAnyChanges(element, ex);
            }
            
        }
    }

    public class CannotObserveAnyChanges:ApplicationException
    {
{'fraction_non_alphanumeric': 0.0823288605867637, 'fraction_numerical': 0.0034114168751421424, 'mean_word_length': 1.8915187376725837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5926531', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1097, 'n_words': 199}