-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_debugger.ps1
More file actions
77 lines (65 loc) · 2.41 KB
/
Copy pathrun_debugger.ps1
File metadata and controls
77 lines (65 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
$jsonList = Invoke-RestMethod -Uri 'http://localhost:9222/json/list'
$page = $jsonList | Where-Object { $_.url -like "*sistemateos.github.oi*" }
if (-not $page) {
Write-Host "No se encontro la pagina en Chrome Headless." -ForegroundColor Red
exit
}
$wsUrl = $page.webSocketDebuggerUrl
Write-Host "Conectando al WebSocket de depuracion: $wsUrl" -ForegroundColor Cyan
$htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<title>Debugger</title>
<script>
var fso = new ActiveXObject("Scripting.FileSystemObject");
var logFile = fso.CreateTextFile("c:\\Users\\misae\\Downloads\\SISTEMA TEOS\\SISTEMA TEOS\\console_logs.txt", true);
logFile.WriteLine("=== LOGS DE CONSOLA DE CHROME ===");
var ws = new WebSocket("$wsUrl");
ws.onopen = function() {
logFile.WriteLine("[WS] Conectado.");
ws.send(JSON.stringify({ id: 1, method: "Runtime.enable" }));
ws.send(JSON.stringify({ id: 2, method: "Log.enable" }));
};
ws.onmessage = function(event) {
var data = JSON.parse(event.data);
if (data.method === "Runtime.consoleAPICalled") {
var args = data.params.args.map(function(a) { return a.value || JSON.stringify(a); }).join(" ");
logFile.WriteLine("[CONSOLE] " + args);
}
if (data.method === "Log.entryAdded") {
logFile.WriteLine("[LOG] " + data.params.entry.text);
}
};
ws.onerror = function(err) {
logFile.WriteLine("[ERROR WS] " + JSON.stringify(err));
};
setTimeout(function() {
logFile.Close();
window.close();
}, 3000);
</script>
</head>
<body>
<h3>Depurando...</h3>
</body>
</html>
"@
Set-Content -Path "temp_debugger.html" -Value $htmlContent
# Execute HTApp
Start-Process "mshta.exe" -ArgumentList "c:\Users\misae\Downloads\SISTEMA TEOS\SISTEMA TEOS\temp_debugger.html"
Start-Sleep -Seconds 5
if (Test-Path "console_logs.txt") {
Get-Content "console_logs.txt"
} else {
Write-Host "No se pudo generar console_logs.txt" -ForegroundColor Red
}
# Cleanup
Remove-Item "temp_debugger.html" -ErrorAction SilentlyContinue
# Stop Chrome
$chromeProcesses = Get-Process -Name "chrome" -ErrorAction SilentlyContinue
foreach ($p in $chromeProcesses) {
if ($p.Path -like "*chrome.exe*") {
$p.Kill()
}
}