diff --git a/geometry/meshcat.cc b/geometry/meshcat.cc index 85a1e9fd5a54..bd9a94ec6fae 100644 --- a/geometry/meshcat.cc +++ b/geometry/meshcat.cc @@ -50,6 +50,14 @@ namespace { using math::RigidTransformd; using math::RotationMatrixd; +// TODO(jwnimmer-tri) Use the C++ built-in ends_with when we drop C++17. +bool EndsWith(std::string_view str, std::string_view suffix) { + if (str.size() < suffix.size()) { + return false; + } + return str.substr(str.size() - suffix.size()) == suffix; +} + template [[noreturn]] void ThrowThingNotFound(std::string_view thing, std::string_view name, Mapping thing_map) { @@ -1922,6 +1930,8 @@ class Meshcat::Impl { internal::GetMeshcatStaticResource(url_path)) { if (content->substr(0, 15) == "") { response->writeHeader("Content-Type", "text/html; charset=utf-8"); + } else if (EndsWith(url_path, ".js")) { + response->writeHeader("Content-Type", "text/javascript; charset=utf-8"); } response->end(*content); return; diff --git a/geometry/meshcat.h b/geometry/meshcat.h index 8dcb1f531e8a..c4b075fef463 100644 --- a/geometry/meshcat.h +++ b/geometry/meshcat.h @@ -162,6 +162,9 @@ for or [Firefox](https://addons.mozilla.org/en-US/firefox/addon/webxr-api-emulator/)). +The AR/VR mode is not currently supported in offline mode (i.e., when saving as +StaticHtml()). + @section network_access Network access See MeshcatParams for options to control the hostname and port to bind to. diff --git a/geometry/meshcat.html b/geometry/meshcat.html index 151a83da0667..52fd1f77ccb7 100644 --- a/geometry/meshcat.html +++ b/geometry/meshcat.html @@ -215,7 +215,11 @@ url = url.replace("/index.html", "/") url = url.replace("/meshcat.html", "/") make_connection(url, reconnect_ms); - + + // Per our meshcat.h docs, using XR when offline is not supported. Adding + // offline support might be possible by moving the 'webxr' and 'controller' + // handling outside of the CONNECTION BLOCK comment region and adding + // meshcat_manual_test coverage. const webxrMode = urlParams.get('webxr'); if (webxrMode) { @@ -231,8 +235,7 @@ type: "visualize_vr_controller" }); } - - + diff --git a/geometry/test/meshcat_manual_test.cc b/geometry/test/meshcat_manual_test.cc index c44e91f491ba..269307862ec3 100644 --- a/geometry/test/meshcat_manual_test.cc +++ b/geometry/test/meshcat_manual_test.cc @@ -203,6 +203,23 @@ int do_main() { } } + std::cout << R"""( +Open the developer tools of your browser (F12) and within that panel switch to +the "Console" tab. + +Keep that panel visible throughout the entire testing process. Any errors or +warnings displayed in that Console most likely indicate a bug in our code and +should be fixed. (If you are running this test as part of a pull request code +review, be sure to post the message as a Reviewable discussion.) + +Less severe Console messages (info, debug, etc.) are not bugs and can be +ignored. + +Caveat: At the moment, you might see Console warnings related to deprecations. +Ignore those for now; we'll need to circle back and fix them later. +)"""; + MaybePauseForUser(); + std::cout << R"""( - The background should be grey. - From left to right along the x axis, you should see: @@ -456,8 +473,11 @@ int do_main() { "- the camera is focused on the contact point between the robot and " "table,\n" "- the iiwa is visible,\n" - "- the animation plays, and\n" - "- the environment map is present.\n"; + "- the animation plays,\n" + "- the environment map is present, and\n" + "- the browser Console has no warnings nor errors\n" + " (use F12 to open the panel with the Console).\n\n"; + std::cout << "When you're done, close the browser tab.\n"; MaybePauseForUser();