-
Notifications
You must be signed in to change notification settings - Fork 84
chore: browserserver #643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: browserserver #643
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -82,28 +82,32 @@ export class ReusedBrowser implements vscodeTypes.Disposable { | |||||
return {}; | ||||||
} | ||||||
|
||||||
const args = [ | ||||||
config.cli, | ||||||
'run-server', | ||||||
`--path=/${createGuid()}` | ||||||
]; | ||||||
const cwd = config.workspaceFolder; | ||||||
const envProvider = () => ({ | ||||||
...this._envProvider(), | ||||||
PW_CODEGEN_NO_INSPECTOR: '1', | ||||||
PW_EXTENSION_MODE: '1', | ||||||
}); | ||||||
let backend = await this._connectToBrowserServer(); | ||||||
if (!backend) { | ||||||
const args = [ | ||||||
config.cli, | ||||||
'run-server', | ||||||
`--path=/${createGuid()}` | ||||||
]; | ||||||
const cwd = config.workspaceFolder; | ||||||
const envProvider = () => ({ | ||||||
...this._envProvider(), | ||||||
PW_CODEGEN_NO_INSPECTOR: '1', | ||||||
PW_EXTENSION_MODE: '1', | ||||||
}); | ||||||
|
||||||
const errors: string[] = []; | ||||||
const backendServer = new BackendServer(this._vscode, () => new Backend(this._vscode), { | ||||||
args, | ||||||
cwd, | ||||||
envProvider, | ||||||
errors, | ||||||
}); | ||||||
backend = await backendServer.startAndConnect(); | ||||||
if (!backend) | ||||||
return { errors }; | ||||||
} | ||||||
|
||||||
const errors: string[] = []; | ||||||
const backendServer = new BackendServer(this._vscode, () => new Backend(this._vscode), { | ||||||
args, | ||||||
cwd, | ||||||
envProvider, | ||||||
errors, | ||||||
}); | ||||||
const backend = await backendServer.startAndConnect(); | ||||||
if (!backend) | ||||||
return { errors }; | ||||||
backend.onClose(() => { | ||||||
if (backend === this._backend) { | ||||||
this._backend = undefined; | ||||||
|
@@ -191,6 +195,24 @@ export class ReusedBrowser implements vscodeTypes.Disposable { | |||||
return {}; | ||||||
} | ||||||
|
||||||
private async _connectToBrowserServer(): Promise<Backend | null> { | ||||||
try { | ||||||
const baseURL = new URL('http://localhost:14518'); | ||||||
const response = await fetch(new URL('/json', baseURL)); | ||||||
if (!response.ok) | ||||||
return null; | ||||||
const json = await response.json(); | ||||||
if (typeof json.wsEndpointPath !== 'string') | ||||||
return null; | ||||||
const client = new Backend(this._vscode); | ||||||
await client._connect(baseURL.toString()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The returned
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
return client; | ||||||
} catch (e) { | ||||||
console.error('Failed to connect to browser server:', e); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Using Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
return null; | ||||||
} | ||||||
} | ||||||
|
||||||
private _scheduleEdit(callback: () => Promise<void>) { | ||||||
this._editOperations = this._editOperations.then(callback).catch(e => console.log(e)); | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Hardcoding the browser server URL and port limits flexibility; consider extracting the host/port into a config or environment variable.
Copilot uses AI. Check for mistakes.