Fix a bug with detecting the base path for DevTools assets (#8826)

diff --git a/packages/devtools_app/lib/src/shared/primitives/utils.dart b/packages/devtools_app/lib/src/shared/primitives/utils.dart
index 72d9567..0dab37a 100644
--- a/packages/devtools_app/lib/src/shared/primitives/utils.dart
+++ b/packages/devtools_app/lib/src/shared/primitives/utils.dart
@@ -1114,10 +1114,13 @@
 ///     ==> 'http://127.0.0.1:61962/mb9Sw4gCYvU=/devtools'
 /// * 'http://127.0.0.1:61962/performance' ==> 'http://127.0.0.1:61962'
 String devtoolsAssetsBasePath({required String origin, required String path}) {
+  // Ensure that we are truly only using the origin of the URI String passed as
+  // the [origin] parameter.
+  final trimmedOrigin = Uri.parse(origin).origin;
   const separator = '/';
   final pathParts = path.split(separator);
   // The last path part is the DevTools page (e.g. 'performance' or 'snapshot'),
   // which is not part of the hosted asset path.
   pathParts.removeLast();
-  return '$origin${pathParts.join(separator)}';
+  return '$trimmedOrigin${pathParts.join(separator)}';
 }
diff --git a/packages/devtools_app/test/shared/primitives/utils_test.dart b/packages/devtools_app/test/shared/primitives/utils_test.dart
index b8d1ad9..600c590 100644
--- a/packages/devtools_app/test/shared/primitives/utils_test.dart
+++ b/packages/devtools_app/test/shared/primitives/utils_test.dart
@@ -1336,6 +1336,22 @@
       ),
       equals('http://127.0.0.1:61962'),
     );
+    // This is how a DevTools url will be structured when DevTools is ran
+    // locally using `dt run`.
+    expect(
+      devtoolsAssetsBasePath(origin: 'http://127.0.0.1:9100/', path: '/home'),
+      equals('http://127.0.0.1:9100'),
+    );
+    // This is how a DevTools url will be structured when it has query
+    // parameters (e.g. when it is connected to an app).
+    expect(
+      devtoolsAssetsBasePath(
+        origin:
+            'http://127.0.0.1:9100/home?uri=ws://127.0.0.1:50416/Hnr3zwp99d0=/ws',
+        path: '/home',
+      ),
+      equals('http://127.0.0.1:9100'),
+    );
   });
 }