Skip to content

Commit 70bb4f6

Browse files
authored
Fixed the process detection logic for Windows for the DevTools plugin (#843)
* Fixed the process detection logic for Windows * Improved exception logic in DevToolsPlugin * Removed unnecessary namespace
1 parent 7f8155e commit 70bb4f6

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

dev-proxy-plugins/Inspection/DevToolsPlugin.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public enum PreferredBrowser
1717
{
1818
Edge,
1919
Chrome,
20-
EdgeDev
20+
EdgeDev,
21+
EdgeBeta
2122
}
2223

2324
public class DevToolsPluginConfiguration
@@ -82,6 +83,7 @@ private string GetBrowserPath(DevToolsPluginConfiguration configuration)
8283
PreferredBrowser.Chrome => Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\Google\Chrome\Application\chrome.exe"),
8384
PreferredBrowser.Edge => Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"),
8485
PreferredBrowser.EdgeDev => Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft\Edge Dev\Application\msedge.exe"),
86+
PreferredBrowser.EdgeBeta => Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft\Edge Beta\Application\msedge.exe"),
8587
_ => throw new NotSupportedException($"{configuration.PreferredBrowser} is an unsupported browser. Please change your PreferredBrowser setting for {Name}.")
8688
};
8789
}
@@ -92,6 +94,7 @@ private string GetBrowserPath(DevToolsPluginConfiguration configuration)
9294
PreferredBrowser.Chrome => "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
9395
PreferredBrowser.Edge => "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
9496
PreferredBrowser.EdgeDev => "/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev",
97+
PreferredBrowser.EdgeBeta => "/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Beta",
9598
_ => throw new NotSupportedException($"{configuration.PreferredBrowser} is an unsupported browser. Please change your PreferredBrowser setting for {Name}.")
9699
};
97100
}
@@ -102,6 +105,7 @@ private string GetBrowserPath(DevToolsPluginConfiguration configuration)
102105
PreferredBrowser.Chrome => "/opt/google/chrome/chrome",
103106
PreferredBrowser.Edge => "/opt/microsoft/msedge/msedge",
104107
PreferredBrowser.EdgeDev => "/opt/microsoft/msedge-dev/msedge",
108+
PreferredBrowser.EdgeBeta => "/opt/microsoft/msedge-beta/msedge",
105109
_ => throw new NotSupportedException($"{configuration.PreferredBrowser} is an unsupported browser. Please change your PreferredBrowser setting for {Name}.")
106110
};
107111
}
@@ -113,9 +117,17 @@ private string GetBrowserPath(DevToolsPluginConfiguration configuration)
113117

114118
private Process[] GetBrowserProcesses(string browserPath)
115119
{
116-
return Process.GetProcesses().Where(p =>
117-
p.MainModule is not null && p.MainModule.FileName == browserPath
118-
).ToArray();
120+
return Process.GetProcesses().Where(p => {
121+
try
122+
{
123+
return p.MainModule is not null && p.MainModule.FileName == browserPath;
124+
}
125+
catch (Exception ex)
126+
{
127+
Logger.LogDebug("Error while checking process: {Ex}", ex.Message);
128+
return false;
129+
}
130+
}).ToArray();
119131
}
120132

121133
private void InitInspector()

0 commit comments

Comments
 (0)