@puberty-labs/clits
Version:
CLiTS (Chrome Logging and Inspection Tool Suite) is a powerful Node.js library for automated Chrome browser testing, logging, and inspection. It provides a comprehensive suite of tools for monitoring network requests, console logs, DOM mutations, and more
117 lines (116 loc) • 4.3 kB
JavaScript
import { ChromeExtractor } from './chrome-extractor.js';
import { ChromeAutomation } from './chrome-automation.js';
export class DevIntegration {
constructor(options = {}) {
this.isInitialized = false;
this.options = {
enabled: true,
port: 9222,
host: 'localhost',
monitorReact: true,
monitorRedux: true,
monitorGraphQL: true,
monitorWebSockets: true,
monitorJWT: true,
monitorPerformance: true,
monitorEventLoop: true,
monitorUserInteractions: true,
monitorDOM: true,
monitorCSS: true,
enableAutomation: false,
outputToConsole: true,
...options
};
this.extractor = new ChromeExtractor({
port: this.options.port,
host: this.options.host,
enableReactHookMonitoring: this.options.monitorReact,
includeReduxMonitoring: this.options.monitorRedux,
includeGraphqlMonitoring: this.options.monitorGraphQL,
includeWebSockets: this.options.monitorWebSockets,
includeJwtMonitoring: this.options.monitorJWT,
includePerformanceMonitoring: this.options.monitorPerformance,
includeEventLoopMonitoring: this.options.monitorEventLoop,
includeUserInteractionRecording: this.options.monitorUserInteractions,
includeDomMutationMonitoring: this.options.monitorDOM,
includeCssChangeMonitoring: this.options.monitorCSS,
filters: {
logLevels: this.options.logLevels,
keywords: this.options.keywords,
excludePatterns: this.options.excludePatterns
}
});
if (this.options.enableAutomation) {
this.automation = new ChromeAutomation(this.options.port || 9222);
}
}
static getInstance(options) {
if (!DevIntegration.instance) {
DevIntegration.instance = new DevIntegration(options);
}
return DevIntegration.instance;
}
async initialize() {
if (this.isInitialized)
return;
try {
// Initialize extractor
await this.extractor.extract();
// Initialize automation if enabled
if (this.options.enableAutomation && this.options.automationScript && this.automation) {
await this.automation.runAutomation({
scriptPath: this.options.automationScript,
monitor: true
});
}
this.isInitialized = true;
console.log('[CLITS] Development integration initialized successfully');
}
catch (error) {
console.error('[CLITS] Failed to initialize development integration:', error);
throw error;
}
}
async captureDebugData() {
if (!this.isInitialized) {
await this.initialize();
}
try {
const logs = await this.extractor.extract();
if (this.options.outputToConsole) {
console.log('[CLITS Debug Data]', logs);
}
if (this.options.outputToFile && this.options.outputPath) {
// Implement file output logic
}
}
catch (error) {
console.error('[CLITS] Failed to capture debug data:', error);
}
}
async runAutomation(scriptPath) {
if (!this.options.enableAutomation || !this.automation) {
throw new Error('Automation is not enabled in the current configuration');
}
try {
await this.automation.runAutomation({
scriptPath,
monitor: true
});
}
catch (error) {
console.error('[CLITS] Automation failed:', error);
throw error;
}
}
async cleanup() {
// Implement cleanup logic
this.isInitialized = false;
}
}
// Export a default instance for easy use
export const clits = DevIntegration.getInstance();
// Export a function to initialize with custom options
export const initializeCLITS = (options) => {
return DevIntegration.getInstance(options);
};