Skip to content

Commit

Permalink
Fixed the process detection logic for Windows for the DevTools plugin (
Browse files Browse the repository at this point in the history
…#843)

* Fixed the process detection logic for Windows

* Improved exception logic in DevToolsPlugin

* Removed unnecessary namespace
  • Loading branch information
qmatteoq authored Aug 9, 2024
1 parent 7f8155e commit 70bb4f6
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions dev-proxy-plugins/Inspection/DevToolsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public enum PreferredBrowser
{
Edge,
Chrome,
EdgeDev
EdgeDev,
EdgeBeta
}

public class DevToolsPluginConfiguration
Expand Down Expand Up @@ -82,6 +83,7 @@ private string GetBrowserPath(DevToolsPluginConfiguration configuration)
PreferredBrowser.Chrome => Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\Google\Chrome\Application\chrome.exe"),
PreferredBrowser.Edge => Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"),
PreferredBrowser.EdgeDev => Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft\Edge Dev\Application\msedge.exe"),
PreferredBrowser.EdgeBeta => Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft\Edge Beta\Application\msedge.exe"),
_ => throw new NotSupportedException($"{configuration.PreferredBrowser} is an unsupported browser. Please change your PreferredBrowser setting for {Name}.")
};
}
Expand All @@ -92,6 +94,7 @@ private string GetBrowserPath(DevToolsPluginConfiguration configuration)
PreferredBrowser.Chrome => "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
PreferredBrowser.Edge => "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
PreferredBrowser.EdgeDev => "/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev",
PreferredBrowser.EdgeBeta => "/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Beta",
_ => throw new NotSupportedException($"{configuration.PreferredBrowser} is an unsupported browser. Please change your PreferredBrowser setting for {Name}.")
};
}
Expand All @@ -102,6 +105,7 @@ private string GetBrowserPath(DevToolsPluginConfiguration configuration)
PreferredBrowser.Chrome => "/opt/google/chrome/chrome",
PreferredBrowser.Edge => "/opt/microsoft/msedge/msedge",
PreferredBrowser.EdgeDev => "/opt/microsoft/msedge-dev/msedge",
PreferredBrowser.EdgeBeta => "/opt/microsoft/msedge-beta/msedge",
_ => throw new NotSupportedException($"{configuration.PreferredBrowser} is an unsupported browser. Please change your PreferredBrowser setting for {Name}.")
};
}
Expand All @@ -113,9 +117,17 @@ private string GetBrowserPath(DevToolsPluginConfiguration configuration)

private Process[] GetBrowserProcesses(string browserPath)
{
return Process.GetProcesses().Where(p =>
p.MainModule is not null && p.MainModule.FileName == browserPath
).ToArray();
return Process.GetProcesses().Where(p => {
try
{
return p.MainModule is not null && p.MainModule.FileName == browserPath;
}
catch (Exception ex)
{
Logger.LogDebug("Error while checking process: {Ex}", ex.Message);
return false;
}
}).ToArray();
}

private void InitInspector()
Expand Down

0 comments on commit 70bb4f6

Please sign in to comment.