Skip to content

Commit b2d7d46

Browse files
chore: browser windows compatibility (#3130)
Co-authored-by: Wendong-Fan <133094783+Wendong-Fan@users.noreply.github.com>
1 parent 019705f commit b2d7d46

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

camel/toolkits/hybrid_browser_toolkit/ws_wrapper.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,14 @@ async def start(self):
192192
"""Start the WebSocket server and connect to it."""
193193
await self._cleanup_existing_processes()
194194

195+
import platform
196+
197+
use_shell = platform.system() == 'Windows'
195198
npm_check = subprocess.run(
196199
['npm', '--version'],
197200
capture_output=True,
198201
text=True,
202+
shell=use_shell,
199203
)
200204
if npm_check.returncode != 0:
201205
raise RuntimeError(
@@ -208,6 +212,7 @@ async def start(self):
208212
['node', '--version'],
209213
capture_output=True,
210214
text=True,
215+
shell=use_shell,
211216
)
212217
if node_check.returncode != 0:
213218
raise RuntimeError(
@@ -224,6 +229,7 @@ async def start(self):
224229
cwd=self.ts_dir,
225230
capture_output=True,
226231
text=True,
232+
shell=use_shell,
227233
)
228234
if install_result.returncode != 0:
229235
logger.error(f"npm install failed: {install_result.stderr}")
@@ -238,20 +244,24 @@ async def start(self):
238244
cwd=self.ts_dir,
239245
capture_output=True,
240246
text=True,
247+
shell=use_shell,
241248
)
242249
if build_result.returncode != 0:
243250
logger.error(f"TypeScript build failed: {build_result.stderr}")
244251
raise RuntimeError(
245252
f"TypeScript build failed: {build_result.stderr}"
246253
)
247254

255+
# use_shell already defined above
248256
self.process = subprocess.Popen(
249257
['node', 'websocket-server.js'],
250258
cwd=self.ts_dir,
251259
stdout=subprocess.PIPE,
252260
stderr=subprocess.STDOUT,
253261
text=True,
262+
encoding='utf-8',
254263
bufsize=1,
264+
shell=use_shell,
255265
)
256266

257267
self._server_ready_future = asyncio.get_running_loop().create_future()

hatch_build_npm.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"""
2121

2222
import json
23+
import platform
2324
import re
2425
import subprocess
2526
from pathlib import Path
@@ -59,7 +60,8 @@ def _parse_version(self, version_str: str) -> Tuple[int, int, int]:
5960
version_str = version_str.strip().lstrip('v')
6061
match = re.match(r'(\d+)\.(\d+)\.(\d+)', version_str)
6162
if match:
62-
return tuple(map(int, match.groups()))
63+
groups = match.groups()
64+
return (int(groups[0]), int(groups[1]), int(groups[2]))
6365
return (0, 0, 0)
6466

6567
def _check_version_requirement(self, current: str, required: str) -> bool:
@@ -111,13 +113,16 @@ def _check_node_npm_versions(
111113
npm_version = None
112114
versions_ok = True
113115

116+
use_shell = platform.system() == "Windows"
117+
114118
try:
115119
result = subprocess.run(
116120
["node", "--version"],
117121
check=True,
118122
capture_output=True,
119123
text=True,
120124
timeout=30,
125+
shell=use_shell,
121126
)
122127
node_version = result.stdout.strip()
123128
print(f"Found Node.js version: {node_version}")
@@ -132,6 +137,7 @@ def _check_node_npm_versions(
132137
capture_output=True,
133138
text=True,
134139
timeout=30,
140+
shell=use_shell,
135141
)
136142
npm_version = result.stdout.strip()
137143
print(f"Found npm version: {npm_version}")
@@ -173,6 +179,8 @@ def _check_node_npm_versions(
173179

174180
def _run_npm_build_process(self, ts_dir: Path, dist_dir: Path) -> bool:
175181
r"""Run the npm build process."""
182+
use_shell = platform.system() == "Windows"
183+
176184
try:
177185
print("Installing npm dependencies...")
178186
subprocess.run(
@@ -181,6 +189,7 @@ def _run_npm_build_process(self, ts_dir: Path, dist_dir: Path) -> bool:
181189
check=True,
182190
text=True,
183191
timeout=300,
192+
shell=use_shell,
184193
)
185194

186195
print("Building TypeScript...")
@@ -190,6 +199,7 @@ def _run_npm_build_process(self, ts_dir: Path, dist_dir: Path) -> bool:
190199
check=True,
191200
text=True,
192201
timeout=300,
202+
shell=use_shell,
193203
)
194204

195205
print("Installing Playwright browsers...")
@@ -200,6 +210,7 @@ def _run_npm_build_process(self, ts_dir: Path, dist_dir: Path) -> bool:
200210
check=True,
201211
text=True,
202212
timeout=600,
213+
shell=use_shell,
203214
)
204215
print("Playwright browsers installed successfully")
205216
except subprocess.CalledProcessError as e:

0 commit comments

Comments
 (0)