@puberty-labs/clits
Version:
CLiTS (Chrome Logging and Inspection Tool Suite) is a powerful Node.js library for AI-controlled Chrome browser automation, testing, and inspection. Features enhanced CSS selector support (:contains(), XPath), dry-run mode, element discovery tools, and co
59 lines (48 loc) • 2.13 kB
JavaScript
// BSD: Injects a script into the browser context to monitor Redux state changes and actions, reporting them via console logs.
export const REDUX_STATE_MONITOR_SCRIPT = `
(function() {
const findReduxStore = () => {
// Attempt to find Redux store if it's exposed globally (e.g., for debugging or by a specific setup)
// This is a common pattern for applications exposing the store for testing/debugging.
if (window.store && typeof window.store.getState === 'function' && typeof window.store.dispatch === 'function') {
return window.store;
}
return null;
};
const store = findReduxStore();
const devToolsExtension = window.__REDUX_DEVTOOLS_EXTENSION__;
if (store) {
if (devToolsExtension) {
const devTools = devToolsExtension.connect();
// Subscribe to state changes and actions via DevTools extension
devTools.subscribe(message => {
if (message.type === 'DISPATCH' && message.payload) {
// Action dispatched - state monitoring active
} else if (message.type === 'ACTION' && message.payload) {
// State change detected - monitoring active
} else {
}
});
// Dispatch initial state to DevTools if needed
// devTools.init(store.getState());
} else {
console.warn('[CLiTS-Redux-Monitor] Redux DevTools Extension not found. Falling back to patching dispatch.');
// Patch dispatch to monitor actions and state changes
const originalDispatch = store.dispatch;
store.dispatch = function(action) {
const prevState = store.getState();
const result = originalDispatch.apply(this, arguments);
const newState = store.getState();
// Redux action monitoring active (removed noisy logging)
return result;
};
// Subscribe to state changes (alternative/complementary to patching dispatch)
store.subscribe(() => {
// Redux state change monitoring active (removed noisy logging)
});
}
} else {
console.warn('[CLiTS-Redux-Monitor] Redux store not found. Skipping Redux state monitoring.');
}
})();
`;