Skip to content

Commit fca08c1

Browse files
committed
Restrict browser execution in remote environments and simplify launch logic
- prevent installing in wsl/ssh remote - show appropriate warning
1 parent 588d317 commit fca08c1

3 files changed

Lines changed: 31 additions & 174 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gemini-coder",
33
"displayName": "Code Web Chat",
44
"description": "Markdown prompts for chatbots, APIs, and CLIs with seamless integration",
5-
"version": "2026.1118.483",
5+
"version": "2026.1118.479",
66
"scripts": {
77
"build": "tsx scripts/build.mts && tsx scripts/package.mts",
88
"compile": "tsx scripts/build.mts",

‎apps/editor/src/i18n/translations/views/prompt/handlers/handle-run-browser.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
export const translations = {
2+
'views.prompt.handlers.handle-run-browser.remote-not-supported': {
3+
en: 'Running the browser in a remote environment is not supported.',
4+
pl: 'Uruchamianie przeglądarki w środowisku zdalnym nie jest obsługiwane.',
5+
'zh-cn': '不支持在远程环境中运行浏览器。',
6+
ja: 'リモート環境でのブラウザの実行はサポートされていません。',
7+
'zh-tw': '不支援在遠端環境中執行瀏覽器。',
8+
de: 'Die Ausführung des Browsers in einer Remote-Umgebung wird nicht unterstützt.',
9+
es: 'No se admite la ejecución del navegador en un entorno remoto.',
10+
fr: "L'exécution du navigateur dans un environnement distant n'est pas prise en charge.",
11+
'pt-br': 'A execução do navegador em um ambiente remoto não é suportada.',
12+
ru: 'Запуск браузера в удаленной среде не поддерживается.',
13+
ko: '원격 환경에서의 브라우저 실행은 지원되지 않습니다.',
14+
it: "L'esecuzione del browser in un ambiente remoto non è supportata.",
15+
tr: 'Tarayıcının uzak bir ortamda çalıştırılması desteklenmiyor.',
16+
cs: 'Spuštění prohlížeče ve vzdáleném prostředí není podporováno.',
17+
hu: 'A böngésző távoli környezetben való futtatása nem támogatott.',
18+
bg: 'Изпълнението на браузъра в отдалечена среда не се поддържа.'
19+
},
220
'views.prompt.handlers.handle-run-browser.downloading-browser': {
321
en: 'Downloading browser',
422
pl: 'Pobieranie przeglądarki',

‎apps/editor/src/views/prompt/backend/message-handlers/handle-run-browser.ts‎

Lines changed: 12 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -11,198 +11,37 @@ import {
1111
} from '@puppeteer/browsers'
1212
import { t } from '@/i18n'
1313

14-
const is_wsl = () =>
15-
process.platform === 'linux' &&
16-
(vscode.env.remoteName === 'wsl' || /microsoft/i.test(os.release()))
17-
18-
const get_log_tail = (log_path: string) => {
19-
try {
20-
return fs
21-
.readFileSync(log_path, 'utf-8')
22-
.trim()
23-
.split('\n')
24-
.slice(-5)
25-
.join('\n')
26-
} catch {
27-
return ''
28-
}
29-
}
30-
31-
const chrome_debian_packages = [
32-
'libnss3',
33-
'libatk1.0-0',
34-
'libatk-bridge2.0-0',
35-
'libcups2',
36-
'libdrm2',
37-
'libxkbcommon0',
38-
'libxcomposite1',
39-
'libxdamage1',
40-
'libxfixes3',
41-
'libxrandr2',
42-
'libgbm1'
43-
]
44-
45-
const get_distro_ids = (): string[] => {
46-
try {
47-
const content = fs.readFileSync('/etc/os-release', 'utf-8')
48-
const ids: string[] = []
49-
for (const line of content.split('\n')) {
50-
const match = line.match(/^(ID|ID_LIKE)=(.*)$/)
51-
if (match) {
52-
ids.push(
53-
...match[2]
54-
.replace(/["']/g, '')
55-
.trim()
56-
.toLowerCase()
57-
.split(/\s+/)
58-
.filter(Boolean)
59-
)
60-
}
61-
}
62-
return ids
63-
} catch {
64-
return []
65-
}
66-
}
67-
68-
const get_install_command = (): string | undefined => {
69-
const ids = get_distro_ids()
70-
const is_distro = (...names: string[]) =>
71-
names.some((name) => ids.includes(name))
72-
73-
if (is_distro('debian', 'ubuntu')) {
74-
const asound_package =
75-
'$(apt-cache show libasound2t64 >/dev/null 2>&1 && echo libasound2t64 || echo libasound2)'
76-
return `sudo apt-get update && sudo apt-get install -y ${chrome_debian_packages.join(' ')} ${asound_package}`
77-
}
78-
79-
if (is_distro('fedora', 'rhel', 'centos')) {
80-
return 'sudo dnf install -y nss atk at-spi2-atk cups-libs libdrm libxkbcommon libXcomposite libXdamage libXfixes libXrandr mesa-libgbm alsa-lib pango cairo'
81-
}
82-
83-
if (is_distro('arch')) {
84-
return 'sudo pacman -S --needed --noconfirm nss atk at-spi2-core cups libdrm libxkbcommon libxcomposite libxdamage libxfixes libxrandr mesa alsa-lib pango cairo'
85-
}
86-
87-
if (is_distro('opensuse', 'suse', 'sles')) {
88-
return 'sudo zypper install -y mozilla-nss libatk-1_0-0 libatk-bridge-2_0-0 cups-libs libdrm2 libxkbcommon0 libXcomposite1 libXdamage1 libXfixes3 libXrandr2 libgbm1 libasound2'
89-
}
90-
91-
return undefined
92-
}
93-
94-
const run_in_terminal = (command: string) => {
95-
const terminal = vscode.window.createTerminal({
96-
name: 'Install browser dependencies'
97-
})
98-
terminal.show()
99-
terminal.sendText(command)
100-
}
101-
102-
const show_launch_error = (reason: string, log_path: string) => {
103-
const log_tail = get_log_tail(log_path)
104-
105-
if (is_wsl() && /shared libraries/i.test(log_tail)) {
106-
const install_command = get_install_command()
107-
if (install_command) {
108-
run_in_terminal(install_command)
109-
return
110-
}
111-
}
112-
113-
const hint = /shared libraries/i.test(log_tail)
114-
? '\nSystem libraries required by Chrome are missing. Install them, e.g. on Ubuntu/Debian: sudo apt install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 (libasound2t64 on newer releases).'
115-
: ''
116-
vscode.window.showErrorMessage(
117-
`Failed to launch Browser: ${reason}${hint}\nLog: ${log_path}${
118-
log_tail ? `\n${log_tail}` : ''
119-
}`
120-
)
121-
}
122-
12314
const launch_browser = (
12415
executable_path: string,
12516
user_data_dir: string,
12617
extension_path: string
127-
): Promise<void> => {
18+
) => {
12819
const args = [
12920
`--user-data-dir=${user_data_dir}`,
13021
`--load-extension=${extension_path}`
13122
]
132-
const env: NodeJS.ProcessEnv = { ...process.env }
13323

13424
if (process.platform === 'darwin') {
13525
args.push('--use-mock-keychain')
13626
} else if (process.platform === 'linux') {
13727
args.push('--password-store=basic')
138-
139-
if (is_wsl()) {
140-
args.push('--no-sandbox', '--disable-dev-shm-usage')
141-
env.DISPLAY ??= ':0'
142-
env.WAYLAND_DISPLAY ??= 'wayland-0'
143-
env.XDG_RUNTIME_DIR ??= '/mnt/wslg/runtime-dir'
144-
}
14528
}
14629

147-
const log_path = path.join(os.homedir(), '.cwc', 'browser.log')
148-
149-
return new Promise<void>((resolve) => {
150-
let settled = false
151-
let timer: NodeJS.Timeout | undefined
152-
153-
const settle = () => {
154-
if (settled) return
155-
settled = true
156-
if (timer) clearTimeout(timer)
157-
resolve()
158-
}
159-
160-
let log_fd: number
161-
try {
162-
log_fd = fs.openSync(log_path, 'w')
163-
} catch {
164-
log_fd = -1
165-
}
166-
167-
try {
168-
const child = spawn(executable_path, args, {
169-
detached: true,
170-
stdio: log_fd >= 0 ? ['ignore', log_fd, log_fd] : 'ignore',
171-
env
172-
})
173-
174-
child.on('error', (error) => {
175-
if (settled) return
176-
show_launch_error(error.message, log_path)
177-
settle()
178-
})
179-
180-
child.on('exit', (code, signal) => {
181-
if (settled) return
182-
if (code !== 0) {
183-
show_launch_error(
184-
`process exited early (${signal ? `signal ${signal}` : `code ${code}`})`,
185-
log_path
186-
)
187-
}
188-
settle()
189-
})
190-
191-
timer = setTimeout(() => {
192-
// Still running after 3s, so startup succeeded
193-
child.unref()
194-
settle()
195-
}, 3000)
196-
} catch (error: any) {
197-
show_launch_error(error.message, log_path)
198-
settle()
199-
} finally {
200-
if (log_fd >= 0) fs.closeSync(log_fd)
201-
}
30+
const child = spawn(executable_path, args, {
31+
detached: true,
32+
stdio: 'ignore'
20233
})
34+
child.unref()
20335
}
20436

20537
export const handle_run_browser = async () => {
38+
if (vscode.env.remoteName) {
39+
vscode.window.showWarningMessage(
40+
t('views.prompt.handlers.handle-run-browser.remote-not-supported')
41+
)
42+
return
43+
}
44+
20645
const cwc_dir = path.join(os.homedir(), '.cwc')
20746

20847
if (!fs.existsSync(cwc_dir)) {

0 commit comments

Comments
 (0)