You can use emscripten API to read the JavaScript window.location object.
#include <emscripten/val.h> ... emscripten::val location = emscripten::val::global("location"); auto host = location["hostname"].as<std::string>(); auto port = location["port"].as<std::string>();