feat(navegator_dashboard): v1+v2 — CDP HTTP client, real Tabs panel, full Network panel
CDP HTTP client (cdp_http.h/cpp): WinSock raw + crude_json. GET /json/version,
/json (list tabs), PUT /json/new (Chrome 137+), GET /json/activate/{id},
/json/close/{id}.
CDP WebSocket client (cdp_ws.h/cpp): RFC 6455 handshake + framing manual,
masked client frames, async dispatcher con queue + wait_response. Soporta
fragmentacion (FIN=0 + continuation), ping/pong, close frame. Stats bytes
in/out + frames in.
Cross-panel session (session_state.h/cpp): selected_browser_port +
selected_tab_id. Cambiar tab cierra/abre NetworkSession.
Tabs panel: real. List + filtro titulo/URL + Refresh + New tab + Focus +
Close + Select (alimenta Network panel).
Network panel: DevTools-like.
- Tabla: Name | Status (color) | Method | Type | Initiator | Size | Time | Waterfall
- Filtros: text + invert + chips (Doc/CSS/JS/XHR/Img/Media/Font/WS/Other) + All toggle
- Toggles: Preserve log, Disable cache, Hide data:, Only failed, Pause/Resume
- Detalle por request: Headers (general + req + res) | Payload | Response (lazy
Network.getResponseBody) | Cookies | Timing | WS Messages (frames in/out)
- Right-click row: Copy URL / Copy as cURL / Copy as fetch
- Status bar: N requests | bytes transferred | resources | Finish | DCL | Load
- Export HAR 1.2 a archivo junto al exe
NetworkSession parsea Network.requestWillBeSent + ExtraInfo, responseReceived
+ ExtraInfo, dataReceived, loadingFinished, loadingFailed, webSocketCreated,
webSocketFrameSent/Received/Closed, Page.frameNavigated (autoclear si !preserve),
domContentEventFired, loadEventFired.
API local extendida (local_api.cpp):
- GET /browser/{port}/version
- GET /browser/{port}/tabs
- POST /browser/{port}/tab/new?url=
- POST /browser/{port}/tab/{id}/focus
- POST /browser/{port}/tab/{id}/close
- GET /browser/{port}/har (HAR 1.2 export de la sesion activa)
Build:
- CMakeLists.txt linka imgui_node_editor solo para reusar crude_json (sin
codigo de node-editor en runtime).
- 15 MB exe Windows. Cross-compile mingw-w64 OK.
app.md: bump version 0.2.0 -> 0.3.0, panels matrix actualizado, e2e_checks
añade api_health + api_browsers (warning).
Issue 0002 (sub-issue del roadmap navegator_dashboard 0001).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+154
@@ -5,11 +5,14 @@
|
||||
#include "local_api.h"
|
||||
#include "chrome_scanner.h"
|
||||
#include "chrome_launcher.h"
|
||||
#include "cdp_http.h"
|
||||
#include "session_state.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
@@ -219,12 +222,163 @@ Response handle_not_found(const std::string& path) {
|
||||
return r;
|
||||
}
|
||||
|
||||
// ---------- /browser/{port}/... handlers ----------
|
||||
Response handle_browser_version(int port) {
|
||||
Response r;
|
||||
CdpVersion v; std::string err;
|
||||
if (!cdp_get_version(port, v, &err)) {
|
||||
r.status = 502;
|
||||
r.body = std::string("{\"ok\":false,\"error\":\"") + json_escape(err) + "\"}";
|
||||
return r;
|
||||
}
|
||||
std::ostringstream os;
|
||||
os << "{\"ok\":true"
|
||||
<< ",\"browser\":\"" << json_escape(v.browser) << "\""
|
||||
<< ",\"protocolVersion\":\"" << json_escape(v.protocol_version) << "\""
|
||||
<< ",\"userAgent\":\"" << json_escape(v.user_agent) << "\""
|
||||
<< ",\"v8Version\":\"" << json_escape(v.v8_version) << "\""
|
||||
<< ",\"webkitVersion\":\"" << json_escape(v.webkit_version) << "\""
|
||||
<< ",\"webSocketDebuggerUrl\":\"" << json_escape(v.browser_ws_url) << "\""
|
||||
<< "}";
|
||||
r.body = os.str();
|
||||
return r;
|
||||
}
|
||||
|
||||
Response handle_browser_tabs(int port) {
|
||||
Response r;
|
||||
std::vector<CdpTab> tabs; std::string err;
|
||||
if (!cdp_list_tabs(port, tabs, &err)) {
|
||||
r.status = 502;
|
||||
r.body = std::string("{\"ok\":false,\"error\":\"") + json_escape(err) + "\"}";
|
||||
return r;
|
||||
}
|
||||
std::ostringstream os;
|
||||
os << "[";
|
||||
for (size_t i = 0; i < tabs.size(); ++i) {
|
||||
if (i) os << ",";
|
||||
const auto& t = tabs[i];
|
||||
os << "{\"id\":\"" << json_escape(t.id) << "\""
|
||||
<< ",\"type\":\"" << json_escape(t.type) << "\""
|
||||
<< ",\"title\":\"" << json_escape(t.title) << "\""
|
||||
<< ",\"url\":\"" << json_escape(t.url) << "\""
|
||||
<< ",\"webSocketDebuggerUrl\":\"" << json_escape(t.ws_url) << "\""
|
||||
<< ",\"attached\":" << (t.attached ? "true" : "false")
|
||||
<< "}";
|
||||
}
|
||||
os << "]";
|
||||
r.body = os.str();
|
||||
return r;
|
||||
}
|
||||
|
||||
Response handle_browser_tab_new(int port, const std::map<std::string, std::string>& q) {
|
||||
Response r;
|
||||
std::string url;
|
||||
auto it = q.find("url");
|
||||
if (it != q.end()) url = it->second;
|
||||
CdpTab t; std::string err;
|
||||
if (!cdp_new_tab(port, url, t, &err)) {
|
||||
r.status = 502;
|
||||
r.body = std::string("{\"ok\":false,\"error\":\"") + json_escape(err) + "\"}";
|
||||
return r;
|
||||
}
|
||||
std::ostringstream os;
|
||||
os << "{\"ok\":true,\"id\":\"" << json_escape(t.id) << "\""
|
||||
<< ",\"webSocketDebuggerUrl\":\"" << json_escape(t.ws_url) << "\""
|
||||
<< ",\"url\":\"" << json_escape(t.url) << "\"}";
|
||||
r.body = os.str();
|
||||
return r;
|
||||
}
|
||||
|
||||
Response handle_browser_tab_focus(int port, const std::string& tab_id) {
|
||||
Response r;
|
||||
std::string err;
|
||||
if (!cdp_activate_tab(port, tab_id, &err)) {
|
||||
r.status = 502;
|
||||
r.body = std::string("{\"ok\":false,\"error\":\"") + json_escape(err) + "\"}";
|
||||
return r;
|
||||
}
|
||||
r.body = "{\"ok\":true}";
|
||||
return r;
|
||||
}
|
||||
|
||||
Response handle_browser_tab_close(int port, const std::string& tab_id) {
|
||||
Response r;
|
||||
std::string err;
|
||||
if (!cdp_close_tab(port, tab_id, &err)) {
|
||||
r.status = 502;
|
||||
r.body = std::string("{\"ok\":false,\"error\":\"") + json_escape(err) + "\"}";
|
||||
return r;
|
||||
}
|
||||
r.body = "{\"ok\":true}";
|
||||
return r;
|
||||
}
|
||||
|
||||
Response handle_browser_har(int port) {
|
||||
Response r;
|
||||
NetworkSession* net = nullptr;
|
||||
int sel_port = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(g_session().mu);
|
||||
sel_port = g_session().selected_port;
|
||||
net = g_session().net.get();
|
||||
}
|
||||
if (sel_port != port || !net) {
|
||||
r.status = 409;
|
||||
r.body = "{\"ok\":false,\"error\":\"no active network session for this port (use UI to Select tab first)\"}";
|
||||
return r;
|
||||
}
|
||||
r.body = net->export_har_json();
|
||||
return r;
|
||||
}
|
||||
|
||||
// Routes /browser/{port}/... — devuelve true si el path matchea (out llena la
|
||||
// resp). Si false, fallback al dispatch root.
|
||||
bool route_browser(const std::string& method,
|
||||
const std::string& path,
|
||||
const std::map<std::string, std::string>& q,
|
||||
Response& out) {
|
||||
if (path.compare(0, 9, "/browser/") != 0) return false;
|
||||
size_t pos = 9;
|
||||
size_t slash = path.find('/', pos);
|
||||
std::string port_s = (slash == std::string::npos) ? path.substr(pos) : path.substr(pos, slash - pos);
|
||||
int port = 0;
|
||||
try { port = std::stoi(port_s); } catch (...) { return false; }
|
||||
if (port <= 0) return false;
|
||||
std::string rest = (slash == std::string::npos) ? "" : path.substr(slash);
|
||||
|
||||
// /browser/{port}/version
|
||||
if (method == "GET" && rest == "/version") { out = handle_browser_version(port); return true; }
|
||||
// /browser/{port}/tabs
|
||||
if (method == "GET" && rest == "/tabs") { out = handle_browser_tabs(port); return true; }
|
||||
// /browser/{port}/tab/new
|
||||
if (method == "POST" && rest == "/tab/new"){ out = handle_browser_tab_new(port, q); return true; }
|
||||
// /browser/{port}/tab/{id}/focus|close
|
||||
if (rest.compare(0, 5, "/tab/") == 0) {
|
||||
std::string remainder = rest.substr(5);
|
||||
size_t s2 = remainder.find('/');
|
||||
if (s2 != std::string::npos) {
|
||||
std::string tab_id = remainder.substr(0, s2);
|
||||
std::string action = remainder.substr(s2 + 1);
|
||||
if (method == "POST" && action == "focus") { out = handle_browser_tab_focus(port, tab_id); return true; }
|
||||
if (method == "POST" && action == "close") { out = handle_browser_tab_close(port, tab_id); return true; }
|
||||
}
|
||||
}
|
||||
// /browser/{port}/har
|
||||
if (method == "GET" && rest == "/har") { out = handle_browser_har(port); return true; }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Response dispatch(const std::string& method, const std::string& path, const std::string& query) {
|
||||
auto q = parse_query(query);
|
||||
if (method == "GET" && path == "/health") return handle_health();
|
||||
if (method == "GET" && path == "/browsers") return handle_browsers();
|
||||
if (method == "POST" && path == "/spawn") return handle_spawn(q);
|
||||
if (method == "POST" && path == "/kill") return handle_kill(q);
|
||||
|
||||
Response br;
|
||||
if (route_browser(method, path, q, br)) return br;
|
||||
|
||||
return handle_not_found(path);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user