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:
@@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
|
||||
// CDP WebSocket client minimo (RFC 6455).
|
||||
//
|
||||
// Conexion 1:1 con un target CDP (page/iframe/worker). Usa el url
|
||||
// `webSocketDebuggerUrl` que devuelve `/json`. Solo loopback (127.0.0.1),
|
||||
// asi que sin TLS y handshake simplificado.
|
||||
//
|
||||
// Modelo:
|
||||
// - connect(): handshake HTTP upgrade. Spawn reader thread.
|
||||
// - send_command(method, params_json): envia text frame {"id":N,"method":...,
|
||||
// "params":...}, retorna id. No bloquea.
|
||||
// - wait_response(id, out, ms): bloquea hasta que llega la respuesta con ese
|
||||
// id. Para llamadas one-shot.
|
||||
// - on_message_callback: se invoca por cada frame text recibido (responses
|
||||
// y events). El UI thread lo drena.
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
#ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <winsock2.h>
|
||||
#endif
|
||||
|
||||
namespace navegator {
|
||||
|
||||
struct CdpWsConfig {
|
||||
std::string host = "127.0.0.1";
|
||||
int port = 0;
|
||||
std::string path; // ej. "/devtools/page/ABC123"
|
||||
int timeout_ms = 5000;
|
||||
};
|
||||
|
||||
class CdpWs {
|
||||
public:
|
||||
CdpWs() = default;
|
||||
~CdpWs();
|
||||
|
||||
CdpWs(const CdpWs&) = delete;
|
||||
CdpWs& operator=(const CdpWs&) = delete;
|
||||
|
||||
// Parsea ws://host:port/path. Devuelve false si no es ws://.
|
||||
static bool parse_ws_url(const std::string& url, std::string& host, int& port, std::string& path);
|
||||
|
||||
bool connect(const CdpWsConfig& cfg, std::string* err = nullptr);
|
||||
void close();
|
||||
bool is_connected() const { return running_.load(); }
|
||||
|
||||
// Envia un comando CDP. Devuelve el id asignado o -1 si error.
|
||||
int send_command(const std::string& method, const std::string& params_json = "");
|
||||
|
||||
// Drena la cola de mensajes recibidos. Devuelve hasta `max` y los retira.
|
||||
// Llamar desde UI thread cada frame.
|
||||
std::vector<std::string> drain(size_t max = 256);
|
||||
|
||||
// Bloquea esperando la respuesta del id dado. Devuelve false en timeout.
|
||||
// Solo util para llamadas sincronas (eval, getDocument, etc.) — para el
|
||||
// panel Network preferimos drain().
|
||||
bool wait_response(int id, std::string& out_json, int timeout_ms);
|
||||
|
||||
// Estadisticas (mostrar en UI).
|
||||
uint64_t bytes_in() const { return bytes_in_.load(); }
|
||||
uint64_t bytes_out() const { return bytes_out_.load(); }
|
||||
uint64_t frames_in() const { return frames_in_.load(); }
|
||||
std::string last_error() const { std::lock_guard<std::mutex> lk(err_mu_); return last_err_; }
|
||||
|
||||
private:
|
||||
void reader_loop();
|
||||
bool send_frame_text(const std::string& payload);
|
||||
bool send_close_frame();
|
||||
bool recv_frame(uint8_t& opcode, std::string& payload);
|
||||
bool send_all(const char* data, size_t len);
|
||||
bool recv_n(char* out, size_t n);
|
||||
void set_error(const std::string& e);
|
||||
|
||||
#ifdef _WIN32
|
||||
SOCKET sock_ = INVALID_SOCKET;
|
||||
#else
|
||||
int sock_ = -1;
|
||||
#endif
|
||||
|
||||
std::thread reader_;
|
||||
std::atomic<bool> running_{false};
|
||||
std::atomic<bool> stop_{false};
|
||||
std::atomic<int> next_id_{1};
|
||||
std::atomic<uint64_t> bytes_in_{0};
|
||||
std::atomic<uint64_t> bytes_out_{0};
|
||||
std::atomic<uint64_t> frames_in_{0};
|
||||
|
||||
std::mutex queue_mu_;
|
||||
std::queue<std::string> queue_;
|
||||
|
||||
std::mutex resp_mu_;
|
||||
std::condition_variable resp_cv_;
|
||||
std::unordered_map<int, std::string> responses_;
|
||||
|
||||
std::mutex send_mu_; // serializa envio para no entrelazar frames
|
||||
mutable std::mutex err_mu_;
|
||||
std::string last_err_;
|
||||
};
|
||||
|
||||
} // namespace navegator
|
||||
Reference in New Issue
Block a user