Web Automation Framework (WAF)
🤖 Modern, modüler ve güçlü web automation framework'ü
WAF, Puppeteer tabanlı olarak geliştirilmiş, network interception, WebSocket monitoring, plugin sistemi ve REST API desteği sunan gelişmiş bir web automation framework'üdür.
✨ Özellikler
🌐 Browser Automation
- Chrome Debug Protocol ile gelişmiş browser kontrolü
- Mevcut Chrome instance'ına bağlanma (debug mode)
- Yeni browser instance başlatma seçeneği
- Element interaction (click, type, wait, screenshot)
- JavaScript execution browser context'inde
- Health check ve automatic reconnection
🔄 Network Management
- Request/Response interception Chrome DevTools Protocol ile
- Request modification (headers, body, URL)
- Response capturing ve monitoring
- Custom HTTP requests browser context'inde
- Pattern-based filtering için flexible sistem
🔌 WebSocket Support
- Existing WebSocket monitoring sayfa içindeki bağlantıları yakalama
- Custom WebSocket connections framework üzerinden
- Message pattern matching ve filtering
- Real-time message processing
🧩 Plugin System
- Modüler plugin architecture
- Site-specific strategies (login/logout)
- Action handlers ve custom commands
- Hook system (onConnect, onLogin, etc.)
- Hot reload support
🛠 Session Management
- Automatic login strategies
- Session persistence cookie management
- Site validation ve pattern matching
- Rate limiting ve security features
🌍 REST API
- Full REST API tüm framework fonksiyonları için
- WebSocket server real-time events
- Authentication ve CORS desteği
- Custom endpoints ekleme imkanı
📁 Storage System
- File management encryption support ile
- JSON operations serialize/deserialize
- Data persistence ve backup
- Compression ve optimization
🚀 Hızlı Başlangıç
Kurulum
npm install
Temel Kullanım
const WAF = require('web-automation-framework');
async function example() {
// Framework'ü oluştur
const waf = WAF.create({
browser: {
debugPort: 9222,
headless: false
},
logging: {
level: 'info',
console: true
}
});
try {
// Framework'ü başlat
await waf.init();
// Hedef siteye bağlan
await waf.connect('https://example.com');
// Network request intercept et
waf.network.interceptRequest('api.example.com', (request) => {
request.setHeader('Authorization', 'Bearer token');
return request;
});
// Browser automation
await waf.browser.click('#login-button');
await waf.browser.type('#username', 'myuser');
// Custom action execute et
const result = await waf.execute('example:getData', {
selector: '.data-container'
});
console.log('Result:', result);
} finally {
await waf.shutdown();
}
}
example().catch(console.error);
Chrome Debug Mode Başlatma
Framework mevcut Chrome instance'ına bağlanabilir:
# Windows
chrome.exe --remote-debugging-port=9222 --user-data-dir="C:/chrome-debug"
# macOS
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir="/tmp/chrome-debug"
# Linux
google-chrome --remote-debugging-port=9222 --user-data-dir="/tmp/chrome-debug"
📖 Dokümantasyon
Konfigürasyon
Framework çeşitli konfigurasyon seçenekleri sunar:
const config = {
browser: {
debugPort: 9222, // Chrome debug port
headless: false, // Headless mode
timeout: 30000, // Default timeout
viewport: { width: 1920, height: 1080 }
},
network: {
enabled: true, // Network interception aktif
enableRequestModification: true,
enableResponseCapture: true
},
websocket: {
enabled: true, // WebSocket monitoring
monitorExisting: true, // Sayfa içi WS'leri izle
enableCustomConnections: true
},
session: {
sessionTimeout: 3600000, // 1 saat
maxLoginAttempts: 3
},
logging: {
level: 'info', // error, warn, info, debug, trace
console: true,
file: false
},
api: {
enabled: false, // REST API server
port: 3000
}
};
Network Interception
Gelişmiş network interception özellikleri:
// Request interception
waf.network.interceptRequest('api.example.com', async (request) => {
// Header ekle
request.setHeader('X-Custom', 'value');
// Body modifiye et
request.modifyBody({ extraField: 'value' });
// URL değiştir
request.setUrl(request.url + '?modified=true');
return request;
});
// Response monitoring
waf.network.onResponse('api.example.com', (response) => {
console.log('Response Status:', response.status);
console.log('Response URL:', response.url);
// Yanıtın ait olduğu orijinal isteğin ID'sine erişim (NetworkManager'daki iyileştirme sayesinde)
if (response.requestId) {
console.log('Original Request ID:', response.requestId);
const originalRequest = waf.network.pendingRequests.get(response.requestId);
if (originalRequest) {
console.log('Original Request Method:', originalRequest.method);
}
}
try {
const data = response.json();
console.log('Response Data:', data);
} catch (e) {
console.error('Response body JSON olarak parse edilemedi:', e.message);
console.log('Raw Response Body:', response.text());
}
});
// Custom request gönder
const response = await waf.network.sendRequest({
url: 'https://api.example.com/data',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: { key: 'value' }
});
WebSocket Operations
WebSocket bağlantıları ve mesaj monitoring:
// Existing WebSocket'leri monitor et
waf.websocket.onMessage('socket.example.com', (message) => {
console.log('WebSocket message:', message.parsed);
});
// Custom WebSocket bağlantısı
const connection = await waf.websocket.connect('wss://socket.example.com');
connection.send(JSON.stringify({ type: 'hello' }));
Plugin Development
Kendi plugin'lerinizi geliştirin:
class MyPlugin {
constructor(framework) {
this.framework = framework;
this.name = 'MyPlugin';
this.version = '1.0.0';
// Site patterns
this.sitePatterns = ['mysite.com'];
// Actions
this.actions = {
'my:action': this.myAction
};
// Login strategy
this.loginStrategies = {
'mysite.com': {
steps: [
{ type: 'navigate', value: 'https://mysite.com/login' },
{ type: 'input', selector: '#email', value: '{{email}}' },
{ type: 'input', selector: '#password', value: '{{password}}' },
{ type: 'click', selector: '#submit' }
]
}
};
}
async onInit() {
console.log('Plugin başlatıldı');
}
async myAction(params) {
// Custom action implementation
return { success: true, data: params };
}
}
module.exports = MyPlugin;
REST API
Framework REST API ile uzaktan kontrol edilebilir:
// API'yi etkinleştir
const waf = WAF.create({
api: {
enabled: true,
port: 3000,
authentication: {
enabled: true,
secret: 'my-secret-key'
}
}
});
API Endpoints
GET /health
- Health checkGET /api/status
- Framework durumu // -POST /api/tasks
- Yeni task oluştur // TaskManager kaldırıldı // -GET /api/tasks
- Task'ları listele // TaskManager kaldırıldıPOST /api/actions/:actionName
- Action execute etPOST /api/browser/navigate
- Sayfa navigatePOST /api/browser/click
- Element'e tıklaGET /api/browser/screenshot
- Screenshot al
🔧 Gelişmiş Özellikler
Environment Variables
Konfigurasyon environment variables ile de yapılabilir:
WAF_BROWSER_DEBUG_PORT=9222
WAF_BROWSER_HEADLESS=false
WAF_LOGGING_LEVEL=debug
WAF_API_ENABLED=true
WAF_API_PORT=3000
Plugin Directory
Plugin'ler otomatik olarak plugins.pluginDir
(varsayılan: ./plugins
) içinde belirtilen dizinden yüklenir. waf.plugins.loadPlugin()
metodu ile eklentileri tam dosya/klasör yoluyla veya sadece eklenti adıyla yükleyebilirsiniz. Adıyla yüklendiğinde, PluginManager yapılandırılmış dizin içinde ilgili eklentiyi arar.
const waf = WAF.create({
plugins: {
pluginDir: './my-plugins', // İsteğe bağlı, varsayılanı './plugins'
blacklist: ['unwanted-plugin'],
whitelist: ['only-this-plugin']
}
});
// Eklentiyi adıyla yükleme
await waf.plugins.loadPlugin('MyPlugin');
Data Persistence
Framework verilerini otomatik olarak persist eder:
const waf = WAF.create({
storage: {
dataDir: './data',
encryption: true,
encryptionKey: 'my-secret-key'
}
// tasks: { // TaskManager kaldırıldı
// persistTasks: true,
// tasksFile: './data/tasks.json'
// }
});
📚 Örnekler
Daha fazla örnek için examples/
dizinine bakın:
basic-usage.js
- Temel framework kullanımıadvanced-network.js
- Gelişmiş network operationsplugin-development.js
- Plugin geliştirme örneğiapi-usage.js
- REST API kullanımı
🤝 Katkıda Bulunma
- Fork edin
- Feature branch oluşturun (
git checkout -b feature/amazing-feature
) - Commit yapın (
git commit -m 'Add amazing feature'
) - Push edin (
git push origin feature/amazing-feature
) - Pull Request açın
📄 Lisans
Bu proje MIT lisansı ile lisanslanmıştır. Detaylar için LICENSE
dosyasına bakın.
🆘 Destek
- Issues: GitHub issues üzerinden
- Dokümantasyon:
/docs
dizini - Örnekler:
/examples
dizini
Web Automation Framework ile web automation işlemlerinizi bir üst seviyeye taşıyın! 🚀