Skip to content

Automate browser based workflows with AI

rewrite WS url more robustly (#2927)

Jonathan Dobsonc294f338d0ae
diff --git a/skyvern-frontend/src/components/BrowserStream.tsx b/skyvern-frontend/src/components/BrowserStream.tsx
index fd4945d01..1e58b3fcf 100644
--- a/skyvern-frontend/src/components/BrowserStream.tsx
+++ b/skyvern-frontend/src/components/BrowserStream.tsx
@@ -8,19 +8,15 @@ import { useCredentialGetter } from "@/hooks/useCredentialGetter";
import { envCredential } from "@/util/env";
import { toast } from "@/components/ui/use-toast";
import RFB from "@novnc/novnc/lib/rfb.js";
-import { environment } from "@/util/env";
+import { environment, wssBaseUrl, newWssBaseUrl } from "@/util/env";
import { cn } from "@/util/utils";
import { useClientIdStore } from "@/store/useClientIdStore";
import type {
TaskApiResponse,
WorkflowRunStatusApiResponse,
} from "@/api/types";
-
import "./browser-stream.css";
-const wssBaseUrl = import.meta.env.VITE_WSS_BASE_URL;
-const newWssBaseUrl = wssBaseUrl.replace("/api", "");
-
interface CommandTakeControl {
kind: "take-control";
}
diff --git a/skyvern-frontend/src/routes/browserSession/BrowserSession.tsx b/skyvern-frontend/src/routes/browserSession/BrowserSession.tsx
index 8641ff14a..fded8e38a 100644
--- a/skyvern-frontend/src/routes/browserSession/BrowserSession.tsx
+++ b/skyvern-frontend/src/routes/browserSession/BrowserSession.tsx
@@ -20,8 +20,10 @@ function BrowserSession() {
try {
await client.get(`/browser_sessions/${browserSessionId}`);
setHasBrowserSession(true);
+ return true;
} catch (error) {
setHasBrowserSession(false);
+ return false;
}
},
});
diff --git a/skyvern-frontend/src/util/env.ts b/skyvern-frontend/src/util/env.ts
index 661d2069e..faba1b04e 100644
--- a/skyvern-frontend/src/util/env.ts
+++ b/skyvern-frontend/src/util/env.ts
@@ -26,6 +26,19 @@ const lsKeys = {
optimisticBrowserSession: "skyvern.optimisticBrowserSession",
};
+const wssBaseUrl = import.meta.env.VITE_WSS_BASE_URL;
+
+let newWssBaseUrl = wssBaseUrl;
+try {
+ const url = new URL(wssBaseUrl);
+ if (url.pathname.startsWith("/api")) {
+ url.pathname = url.pathname.replace(/^\/api/, "");
+ }
+ newWssBaseUrl = url.toString();
+} catch (e) {
+ newWssBaseUrl = wssBaseUrl.replace("/api", "");
+}
+
export {
apiBaseUrl,
environment,
@@ -33,4 +46,6 @@ export {
artifactApiBaseUrl,
apiPathPrefix,
lsKeys,
+ wssBaseUrl,
+ newWssBaseUrl,
};