-3

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.

1
  • Please see the FAQ on how to ask good questions. Here's what I previously made in this area with Beast: stackoverflow.com/questions/70768742/… - perhaps reading it will give you an idea of where to look/how to proceed Commented Nov 20, 2024 at 12:53

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Wow. Did someone actually downvote this? That's really quite harsh. Why would people even spend the effort anymore. I'm guessing people just /do not/ appreciate how much effort is involved in installing websocketpp, nlohmann, chromium-browser, configuring the project, making it compile, then testing it. Sigh.
It's likely for the text in the picture. I agree with the downvote because the drawn text in the picture on my mobile screen has the height ~0.5 mm and is horrible.
@3CxEZiVlQ It's just that it contains text that cannot be copy pasted. Oh well. I thought downvotes signify "this answer isn't useful", not "there's things I don't like/not ordinarily desired". Besides edits exist. One of those days I guess.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.