c++boost-asio

Google devtools not working with --remote-debugging-port


titles says it all, i cant get it to work, i launched with parameters "chrome.exe --remote-debugging-port=9999" and am attempting to send a websocket request via boost asio in c++, whenever i attempt to access localhost:9999/devtools it also comes up with "localhost was unable to load this page".

test code was generated using AI:

#include <iostream>
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>
#include <nlohmann/json.hpp>

using json = nlohmann::json;
typedef websocketpp::client<websocketpp::config::asio_client> client;

client c; // Global client instance

void on_open(websocketpp::connection_hdl hdl) {
    std::cout << "Connection opened!" << std::endl;

    // Prepare JSON payload for navigation command
    json payload = {
        {"id", 1},
        {"method", "Page.navigate"},
        {"params", {{"url", "http://example.com"}}}
    };

    // Convert JSON payload to string
    std::string message = payload.dump();

    // Send the command
    c.send(hdl, message, websocketpp::frame::opcode::text);
}

void on_message(websocketpp::connection_hdl hdl, client::message_ptr msg) {
    std::cout << "Received message: " << msg->get_payload() << std::endl;
}

void on_close(websocketpp::connection_hdl hdl) {
    std::cout << "Connection closed!" << std::endl;
}

int main() {
    // Initialize ASIO
    c.init_asio();

    // Set handlers
    c.set_open_handler(&on_open);
    c.set_message_handler(&on_message);
    c.set_close_handler(&on_close);

    // Get the correct WebSocket URL from http://localhost:9999/json
    std::string uri = "ws://127.0.0.1:9999/json"; // Replace with actual WebSocket URL from JSON response
    websocketpp::lib::error_code ec;

    client::connection_ptr con = c.get_connection(uri, ec);

    if (ec) {
        std::cout << "Could not create connection because: " << ec.message() << std::endl;
        return 0;
    }

    // Connect and start the ASIO io_service run loop
    c.connect(con);

    try {
        c.run();
    }
    catch (const std::exception& e) {
        std::cout << e.what() << std::endl;
    }

    return 0;
}

ADDITIONAL ERRORS:

[2024-11-20 07:45:07] [connect] Successful connection [2024-11-20 07:45:07] [error] Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.) [2024-11-20 07:45:07] [fail] WebSocket Connection 127.0.0.1:6969 - "WebSocket++/0.8.2" /json 404 websocketpp.processor:20 Invalid HTTP status.


Solution

  • Using this code against

    chromium-brower --remote-debuging-port=6969
    

    Shows:

    enter image description here

    The weird part is /json in your question. It is probably what leads to HTTP 404 error.