A powerful Chrome DevTools Protocol (CDP) automation system with Integuru integration that reverse-engineers web APIs from HAR files to generate executable Python code with 8-15x speed improvements over traditional browser automation.
# Clone the repository
git clone <repository-url>
cd cdp-integuru-automation
# Install dependencies
npm install
# Install Integuru (automated)
npm run install:integuru
# Set up environment
cp .env.example .env
# Edit .env with your OpenAI API keyconst InteguruWrapper = require('./src/lib/integuru-wrapper');
async function automateWorkflow() {
const integuru = new InteguruWrapper();
// Analyze HAR file and generate code
const result = await integuru.analyzeHAR(
'./network_requests.har',
'Download the generated image from KlingAI',
true
);
console.log(`Confidence: ${result.confidence}`);
console.log(`Generated code:\n${result.code}`);
// Execute the generated code
const execution = await integuru.executeCode(result.code);
console.log(`Execution successful: ${execution.success}`);
}
automateWorkflow();- π API Reverse-Engineering: Analyzes HAR files to understand internal APIs
- π Python Code Generation: Generates executable Python code (8-15x faster)
- π Secure Execution: Sandboxed Python environment with security restrictions
- π Dependency Analysis: Builds dependency graphs and identifies critical paths
- πͺ Cookie Handling: Extracts and manages authentication cookies
- β‘ Performance Optimization: Optimizes execution order and parallel processing
- π‘οΈ Security Validation: Validates generated code for security issues
- π Confidence Scoring: Provides confidence scores for generated code
- π§ͺ Comprehensive Testing: Full test suite with sample HAR files
βββ src/
β βββ lib/
β β βββ integuru-wrapper.js # Main wrapper class
β β βββ har-processor.js # HAR file processing
β β βββ code-executor.js # Secure Python execution
β β βββ dependency-analyzer.js # API dependency analysis
β βββ test/
β βββ test-integuru.js # Test suite
β βββ validate-generated-code.js # Code validation
β βββ sample-hars/ # Sample HAR files
β βββ klingai-image-download.har
β βββ ecommerce-checkout.har
βββ scripts/
β βββ install-integuru.sh # Installation script
βββ docs/
β βββ integuru-integration.md # Full documentation
βββ extensions/
β βββ cdp-stealth/ # Chrome extension
βββ package.json # Node.js dependencies
βββ README-integuru.md # This file
Create a .env file:
# OpenAI API Configuration
OPENAI_API_KEY=your_openai_api_key_here
# Integuru Configuration
INTEGURU_MODEL=gpt-4o
INTEGURU_TIMEOUT=30
INTEGURU_TEMP_DIR=./temp
# Code Execution Configuration
CODE_EXECUTOR_TIMEOUT=10
CODE_EXECUTOR_MAX_MEMORY=256mconst integuru = new InteguruWrapper({
model: 'gpt-4o', // OpenAI model (gpt-4o, o1-mini, gpt-3.5-turbo)
timeout: 30000, // Request timeout in ms
tempDir: './temp', // Temporary directory
integuruDir: './Integuru' // Integuru installation directory
});const InteguruWrapper = require('./src/lib/integuru-wrapper');
async function downloadKlingAIImage() {
const integuru = new InteguruWrapper();
const result = await integuru.analyzeHAR(
'./src/test/sample-hars/klingai-image-download.har',
'Download the generated image from KlingAI',
true
);
if (result.confidence > 0.8) {
console.log('High confidence in generated code!');
const execution = await integuru.executeCode(result.code);
if (execution.success) {
console.log('β
Image downloaded successfully!');
}
}
}
downloadKlingAIImage();const InteguruWrapper = require('./src/lib/integuru-wrapper');
async function automateCheckout() {
const integuru = new InteguruWrapper({
model: 'gpt-4o',
timeout: 60000 // Longer timeout for complex workflow
});
const result = await integuru.analyzeHAR(
'./src/test/sample-hars/ecommerce-checkout.har',
'Complete e-commerce checkout process',
true
);
console.log(`π Dependency graph depth: ${result.dependency_graph.depth}`);
console.log(`π API endpoints: ${result.api_endpoints.length}`);
console.log(`π Authentication: ${result.auth_flow.hasAuth ? 'Yes' : 'No'}`);
if (result.auth_flow.hasAuth) {
console.log('π Auth endpoints:', result.auth_flow.authEndpoints);
}
return await integuru.executeCode(result.code);
}const fs = require('fs').promises;
const path = require('path');
const InteguruWrapper = require('./src/lib/integuru-wrapper');
async function batchProcess() {
const integuru = new InteguruWrapper();
const harDir = './har-files';
const files = await fs.readdir(harDir);
const harFiles = files.filter(file => file.endsWith('.har'));
console.log(`Processing ${harFiles.length} HAR files...`);
for (const harFile of harFiles) {
const harPath = path.join(harDir, harFile);
try {
const result = await integuru.analyzeHAR(harPath, `Automate ${harFile}`, true);
console.log(`β
${harFile}: Confidence ${result.confidence}`);
} catch (error) {
console.error(`β ${harFile}: ${error.message}`);
}
}
}
batchProcess();# Run all tests
npm test
# Run Integuru-specific tests
npm run test:integuru
# Validate generated code
npm run test:validateconst InteguruWrapper = require('./src/lib/integuru-wrapper');
async function testWithSamples() {
const integuru = new InteguruWrapper();
// Test KlingAI example
const klingaiResult = await integuru.analyzeHAR(
'./src/test/sample-hars/klingai-image-download.har',
'Download image from KlingAI',
true
);
console.log('KlingAI Result:', klingaiResult.confidence);
// Test e-commerce example
const checkoutResult = await integuru.analyzeHAR(
'./src/test/sample-hars/ecommerce-checkout.har',
'Complete checkout process',
true
);
console.log('Checkout Result:', checkoutResult.confidence);
}
testWithSamples();The system implements multiple security layers:
- Sandboxing: Code runs in isolated process with resource limits
- Module Restrictions: Only allowed modules can be imported
- API Blocking: Dangerous functions like
eval()andexec()are blocked - Resource Limits: Memory and CPU time are constrained
- File System Isolation: Limited file system access
// Validate generated code before execution
const { validateAgainstHar } = require('./src/test/validate-generated-code');
const validation = await validateAgainstHar(generatedCode, harFile);
if (!validation.valid) {
console.error('Security issues detected:', validation.issues);
return;
}
// Execute with minimal permissions
const execution = await integuru.executeCode(generatedCode, {
env: {
// Only provide necessary environment variables
},
timeout: 10000 // Set appropriate timeout
});| Task | Traditional CDP | Integuru API | Speedup |
|---|---|---|---|
| KlingAI image download | 20-30s | 2-3s | 8-10x |
| Form submission | 10-15s | 1-2s | 10-15x |
| Multi-step workflow | 60-90s | 5-10s | 12-18x |
- Use Appropriate Models:
o1-minifor simple tasks,gpt-4ofor complex ones - Optimize HAR Files: Remove unnecessary requests before analysis
- Cache Results: Reuse successful analyses when possible
- Parallel Processing: Process independent workflows in parallel
const HarProcessor = require('./src/lib/har-processor');
const processor = new HarProcessor({
apiPatterns: ['/api/', '/v1/', '/graphql'],
excludeExtensions: ['.js', '.css', '.png']
});
const analysis = await processor.process('./network.har');
console.log('Complexity:', analysis.complexity);const DependencyAnalyzer = require('./src/lib/dependency-analyzer');
const analyzer = new DependencyAnalyzer();
const analysis = await analyzer.analyze(processedHarData);
console.log('Critical paths:', analysis.criticalPaths);
console.log('Recommendations:', analysis.recommendations);const { CodeValidator } = require('./src/test/validate-generated-code');
const validator = new CodeValidator();
const validation = await validator.validate(pythonCode);
if (!validation.valid) {
console.log('Issues:', validation.issues);
console.log('Score:', validation.score);
}- Full Documentation: docs/integuru-integration.md
- API Reference: See inline JSDoc comments
- Examples: Check
src/test/directory - Installation Guide: See
scripts/install-integuru.sh
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
# Install development dependencies
npm install --dev
# Run tests in watch mode
npm run test:watch
# Start development server
npm run dev
# Lint code
npm run lint# Check Python version
python3 --version # Should be 3.8+
# Install Poetry manually
curl -sSL https://install.python-poetry.org | python3 -
# Verify installation
poetry --version// Increase timeout
const integuru = new InteguruWrapper({
timeout: 60000, // 60 seconds
codeTimeout: 30000 // 30 seconds for code execution
});- Ensure HAR file contains complete requests and responses
- Check that authentication flows are properly captured
- Verify API calls are not obfuscated or encrypted
- Try more specific task prompts
// Limit memory usage
const executor = new CodeExecutor({
maxMemory: '128m', // Reduce memory limit
timeout: 5000 // Shorter timeout
});const integuru = new InteguruWrapper({
debug: true,
verbose: true
});
// Enable detailed logging
console.log('Debug mode enabled');MIT License - see LICENSE file for details.
- Integuru - API reverse-engineering
- mitmproxy - Network interception
- rebrowser-patches - CDP stealth
- Chrome DevTools Protocol - Browser automation
- Issues: GitHub Issues
- Documentation: Wiki
- Discussions: GitHub Discussions
β‘ Transform your browser automation with API-first approach - 8-15x faster execution!