Skip to content

Commit 60afe55

Browse files
committed
Add run browser action to enable browser autofill when disconnected
- in Prompt View, above prompt field in WEB target, when not connected: show Status Bar 'Enable autofill in Chrome for Testing? [Run]'. Clicking [Run], sets cwd to [user dir]/.cwc, create dir `browsers` and runs command there: [Pasted text]. This command retuns path of the installed browser. Run it with provided args: [Pasted text] and [Pasted text]. `user data dir` should be in [user dir]/.cwc/browsers/chrome-user-data, `load extension` should be [user dir]/.cwc/repository-[currently run vs code schema]/apps/browser/out - rename 'run chrome for testing' to 'run browser'
1 parent 7462708 commit 60afe55

8 files changed

Lines changed: 159 additions & 1 deletion

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import * as vscode from 'vscode'
2+
import * as path from 'path'
3+
import * as os from 'os'
4+
import * as fs from 'fs'
5+
import { exec, spawn } from 'child_process'
6+
7+
export const handle_run_browser = async () => {
8+
const cwc_dir = path.join(os.homedir(), '.cwc')
9+
const browsers_dir = path.join(cwc_dir, 'browsers')
10+
11+
if (!fs.existsSync(browsers_dir)) {
12+
fs.mkdirSync(browsers_dir, { recursive: true })
13+
}
14+
15+
const scheme = vscode.env.uriScheme
16+
const extension_path = path.join(
17+
cwc_dir,
18+
`repository-${scheme}`,
19+
'apps',
20+
'browser',
21+
'out'
22+
)
23+
const user_data_dir = path.join(browsers_dir, 'chrome-user-data')
24+
25+
vscode.window.withProgress(
26+
{
27+
location: vscode.ProgressLocation.Notification,
28+
title: 'Installing Browser...',
29+
cancellable: false
30+
},
31+
async () => {
32+
return new Promise<void>((resolve, reject) => {
33+
const exec_options: Record<string, any> = { cwd: browsers_dir }
34+
35+
if (process.platform !== 'win32') {
36+
const env = { ...process.env }
37+
if (process.platform === 'darwin') {
38+
env.PATH = `${env.PATH || ''}:/usr/local/bin:/opt/homebrew/bin`
39+
}
40+
exec_options.env = env
41+
if (vscode.env.shell) {
42+
exec_options.shell = vscode.env.shell
43+
}
44+
}
45+
46+
exec(
47+
'npx @puppeteer/browsers install chrome@157',
48+
exec_options,
49+
(error, stdout) => {
50+
if (error) {
51+
vscode.window.showErrorMessage(
52+
`Failed to install Browser: ${error.message}`
53+
)
54+
reject(error)
55+
return
56+
}
57+
58+
const match = stdout.match(/chrome@\S+\s+(.+)/)
59+
const executable_path = match ? match[1].trim() : ''
60+
61+
if (!executable_path || !fs.existsSync(executable_path)) {
62+
vscode.window.showErrorMessage(
63+
`Could not determine Browser path.`
64+
)
65+
reject(new Error('Could not find executable path'))
66+
return
67+
}
68+
69+
const child = spawn(
70+
executable_path,
71+
[
72+
`--user-data-dir=${user_data_dir}`,
73+
`--load-extension=${extension_path}`
74+
],
75+
{
76+
detached: true,
77+
stdio: 'ignore'
78+
}
79+
)
80+
child.unref()
81+
resolve()
82+
}
83+
)
84+
})
85+
}
86+
)
87+
}

‎apps/editor/src/views/prompt/backend/message-handlers/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ export * from './handle-save-targets-order'
7373
export * from './handle-apply'
7474
export * from './handle-get-notes'
7575
export * from './handle-save-notes'
76+
export * from './handle-run-browser'

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
10031003
})
10041004
} else if (message.command === 'AGENTIC_SEARCH') {
10051005
await handle_agentic_search(this)
1006+
} else if (message.command === 'RUN_BROWSER') {
1007+
await handlers.handle_run_browser()
10061008
} else if (message.command === 'SHOW_ACCURACY_BOOST_INFO') {
10071009
await handlers.handle_show_accuracy_boost_info()
10081010
} else if (message.command === 'GET_CLI_CONFIGURATIONS') {

‎apps/editor/src/views/prompt/frontend/Main/Main.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type Props = {
9393
on_agentic_search: () => void
9494
has_update?: boolean
9595
targets_order: Target[]
96+
on_run_browser: () => void
9697
}
9798

9899
export const Main: React.FC<Props> = (props) => {
@@ -803,6 +804,7 @@ export const Main: React.FC<Props> = (props) => {
803804
targets_order={props.targets_order}
804805
can_apply_from_terminal={can_apply_from_terminal}
805806
clipboard_has_applicable_response={clipboard_has_applicable_response}
807+
on_run_browser={props.on_run_browser}
806808
/>
807809
)
808810
}

‎apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ type Props = {
163163
targets_order: Target[]
164164
can_apply_from_terminal: boolean
165165
clipboard_has_applicable_response: boolean
166+
on_run_browser: () => void
166167
}
167168

168169
const chatbot_to_icon: Record<keyof typeof CHATBOTS, Icon.Variant> = {
@@ -417,6 +418,24 @@ export const MainView: React.FC<Props> = (props) => {
417418
}}
418419
/>
419420

421+
{props.target === 'WEB' && !props.is_connected && (
422+
<>
423+
<UiStatusBar
424+
icon="codicon-beaker"
425+
label={t('main.run-browser.enable')}
426+
actions={[
427+
{
428+
id: 'run',
429+
label: t('main.run-browser.run'),
430+
icon: 'codicon-play',
431+
on_click: props.on_run_browser
432+
}
433+
]}
434+
/>
435+
<UiSpacer height={6} />
436+
</>
437+
)}
438+
420439
{is_api_warning_visible && (
421440
<>
422441
<UiStatusBar

‎apps/editor/src/views/prompt/frontend/Prompt.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ export const Prompt = () => {
407407
on_skill_click={handle_skill_click}
408408
on_agentic_search={handle_agentic_search}
409409
targets_order={targets_order}
410+
on_run_browser={() => {
411+
post_message(vscode, { command: 'RUN_BROWSER' })
412+
}}
410413
/>
411414
</div>
412415
<div

‎apps/editor/src/views/prompt/frontend/i18n/translations/main.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,41 @@ export const main = {
178178
cs: 'Ručně aplikováno',
179179
hu: 'Manuálisan alkalmazva',
180180
bg: 'Приложено ръчно'
181+
},
182+
'main.run-browser.enable': {
183+
en: 'Enable autofill in Browser?',
184+
pl: 'Włączyć autouzupełnianie w Przeglądarce?',
185+
'zh-cn': '在浏览器中启用自动填充?',
186+
ja: 'ブラウザで自動入力を有効にしますか?',
187+
'zh-tw': '在瀏覽器中啟用自動填入?',
188+
de: 'Automatisches Ausfüllen im Browser aktivieren?',
189+
es: '¿Habilitar el autocompletado en el Navegador?',
190+
fr: 'Activer la saisie automatique dans le Navigateur ?',
191+
'pt-br': 'Ativar o preenchimento automático no Navegador?',
192+
ru: 'Включить автозаполнение в Браузере?',
193+
ko: '브라우저에서 자동 완성을 활성화하시겠습니까?',
194+
it: 'Abilitare la compilazione automatica nel Browser?',
195+
tr: 'Tarayıcıda otomatik doldurmayı etkinleştir?',
196+
cs: 'Povolit automatické vyplňování v Prohlížeči?',
197+
hu: 'Engedélyezi az automatikus kitöltést a Böngészőben?',
198+
bg: 'Да се активира ли автоматичното попълване в Браузъра?'
199+
},
200+
'main.run-browser.run': {
201+
en: 'Run',
202+
pl: 'Uruchom',
203+
'zh-cn': '运行',
204+
ja: '実行',
205+
'zh-tw': '執行',
206+
de: 'Ausführen',
207+
es: 'Ejecutar',
208+
fr: 'Exécuter',
209+
'pt-br': 'Executar',
210+
ru: 'Запустить',
211+
ko: '실행',
212+
it: 'Esegui',
213+
tr: 'Çalıştır',
214+
cs: 'Spustit',
215+
hu: 'Futtatás',
216+
bg: 'Изпълни'
181217
}
182218
} as const

‎apps/editor/src/views/prompt/types/messages.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { EditFormat } from '@shared/types/edit-format'
2-
import { FileInCodeReview, ItemInCodeReview } from '@shared/types/file-in-code-review'
2+
import {
3+
FileInCodeReview,
4+
ItemInCodeReview
5+
} from '@shared/types/file-in-code-review'
36
import {
47
ResponseHistoryItem,
58
ApiConfigurationDetails,
@@ -655,6 +658,10 @@ export interface AgenticSearchMessage extends BaseMessage {
655658
command: 'AGENTIC_SEARCH'
656659
}
657660

661+
export interface RunBrowserMessage extends BaseMessage {
662+
command: 'RUN_BROWSER'
663+
}
664+
658665
export interface ShowAccuracyBoostInfoMessage extends BaseMessage {
659666
command: 'SHOW_ACCURACY_BOOST_INFO'
660667
}
@@ -820,6 +827,7 @@ export type FrontendMessage =
820827
| PreviewSkillSymbolMessage
821828
| PreviewSavedContextSymbolMessage
822829
| AgenticSearchMessage
830+
| RunBrowserMessage
823831
| ShowAccuracyBoostInfoMessage
824832
| GetAgentConfigurationsMessage
825833
| ReorderAgentConfigurationsMessage

0 commit comments

Comments
 (0)