Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Launch Chrome in unelevated state on Windows platform by using wmic call create. #619

Merged
merged 1 commit into from
Mar 20, 2018

Conversation

changsi-an
Copy link
Contributor

This change is needed because when VS is started in elevated mode, DA will be started in elevated mode too. Any processes launched by DA, in our case Chrome, will be started in elevated mode as well. Chrome is known to have issues with elevated mode.

When DA received shouldLaunchChromeUnelevated launch parameter, it will call cscript.exe to run a customized Windows Script Host program (launchUnelevated.js) to launch chrome process in unelevated mode.

launchUnelevated.js will dump the process id information to a temporary file negotiated with DA, so after the WSH process is finished, DA will poll the content of the file and find out the PID of the launched Chrome process.

@@ -38,7 +38,8 @@ const watchedSources = [
];

const scripts = [
'src/terminateProcess.sh'
'src/terminateProcess.sh',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "teminatePRocess.sh" still needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes as far as I know. It's mac and Linux only

Copy link
Contributor Author

@changsi-an changsi-an Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find src/terminateProcess.sh in the code base. How does it get injected for mac and Linux cases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -38,7 +38,8 @@ const watchedSources = [
];

const scripts = [
'src/terminateProcess.sh'
'src/terminateProcess.sh',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes as far as I know. It's mac and Linux only

@@ -38,7 +38,8 @@ const watchedSources = [
];

const scripts = [
'src/terminateProcess.sh'
'src/terminateProcess.sh',
'src/launchUnelevated.js'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will have to be added to the csproj for signing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the current state of the csproj, when it uses wildcard of ..\out\src\**\* and $(OutDir)\**\*.js, it should include this file too.

@@ -222,7 +225,7 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
// Disconnect before killing Chrome, because running "taskkill" when it's paused sometimes doesn't kill it
super.disconnect(args);

if (this._chromeProc && !hadTerminated) {
if ( (this._chromeProc || (!this._chromeProc && this._chromePID)) && !hadTerminated) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't happen with the current code, but since this can go through when this._chromeProc is null, add a null check below where we call .kill on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Done.


telemetry.telemetry.reportEvent('error', telemetryProperties);

return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to just keep going and try to attach if it can't find the Chrome pid? Or should it throw and fail the launch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, after evaluated two approaches, we reached to a conclusion that we should let the debugging session go as much as it can. Not being able to find process id doesn't necessary mean Chrome is not launched nor non-debuggable. One known side-effect is merely that Chrome can't be closed at the end of the session. Due to current multi-debugger-client design of Chrome, that is not an issue any more.

@@ -0,0 +1,28 @@
var objShell = new ActiveXObject("shell.application");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just going to trust that this is all correct :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use let instead of var.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and I tested it as much as I can. It works.

Unfortunately the Windows Script Host (cscript.exe) is nowhere near any modern ECMAScript standard. let is not supported.

@changsi-an
Copy link
Contributor Author

changsi-an commented Mar 16, 2018

I am in the process of fixing the current build error. Potentially submit another PR to fix the build error first. So please don't merge this PR until the travis build are all green. :)

Guess the build error is already fixed now. So please disregard the above. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants