Skip to content
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

Warn when browser is already running before starting DevTools #694

Closed
karpikpl opened this issue May 8, 2024 · 3 comments
Closed

Warn when browser is already running before starting DevTools #694

karpikpl opened this issue May 8, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request work in progress

Comments

@karpikpl
Copy link
Contributor

karpikpl commented May 8, 2024

Description

I cannot make devtools to work, even though there are no errors logged in devproxy

Expected behaviour

opening http://localhost:9222/devtools/inspector.html?ws=localhost:62690 opens devtools

Actual behaviour

Connection refused. Nothing listening on 9222?

Steps to reproduce

devproxy -c "C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\presets\microsoft-graph.json" --record --log-level Trace

with

  "plugins": [
      {
        "name": "DevToolsPlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "devTools"
      },

Dev Proxy Version

0.17.1

Operating system (environment)

Windows

Shell

PowerShell

Configuration file

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.17.1/rc.schema.json",
  "plugins": [
      {
        "name": "DevToolsPlugin",
        "enabled": true,
        "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
        "configSection": "devTools"
      },
    {
      "name": "GraphSelectGuidancePlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
    },
    {
      "name": "GraphBetaSupportGuidancePlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "urlsToWatch": [
        "https://graph.microsoft.com/beta/*",
        "https://graph.microsoft.us/beta/*",
        "https://dod-graph.microsoft.us/beta/*",
        "https://microsoftgraph.chinacloudapi.cn/beta/*"
      ]
    },
    {
      "name": "GraphConnectorGuidancePlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "urlsToWatch": [
        "https://graph.microsoft.com/*/external/connections/*/schema",
        "https://graph.microsoft.us/*/external/connections/*/schema",
        "https://dod-graph.microsoft.us/*/external/connections/*/schema",
        "https://microsoftgraph.chinacloudapi.cn/*/external/connections/*/schema"
      ]
    },
    {
      "name": "GraphSdkGuidancePlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
    },
    {
      "name": "ODataPagingGuidancePlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
    },
    {
      "name": "GraphClientRequestIdGuidancePlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
    },
    {
      "name": "GraphRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "graphRandomErrorsPlugin"
    },
    {
      "name": "ExecutionSummaryPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "executionSummaryPlugin"
    }
  ],
  "urlsToWatch": [
    "https://graph.microsoft.com/v1.0/*",
    "https://graph.microsoft.com/beta/*",
    "https://graph.microsoft.us/v1.0/*",
    "https://graph.microsoft.us/beta/*",
    "https://dod-graph.microsoft.us/v1.0/*",
    "https://dod-graph.microsoft.us/beta/*",
    "https://microsoftgraph.chinacloudapi.cn/v1.0/*",
    "https://microsoftgraph.chinacloudapi.cn/beta/*"
  ],
  "graphRandomErrorsPlugin": {
    "allowedErrors": [ 429, 500, 502, 503, 504, 507 ]
  },
  "executionSummaryPlugin": {
    "groupBy": "url"
  },
  "devTools": {
    "preferredBrowser": "Chrome"
  },
  "rate": 50,
  "labelMode": "text",
  "logLevel": "information"
}

Additional Info

Log output:

PS C:\Users\piotrkarpala> devproxy -c "C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\presets\microsoft-graph.json" --record --log-level Trace
Loading plugin DevToolsPlugin from: C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\plugins\dev-proxy-plugins.dll
Registering plugin DevToolsPlugin...
DevTools available at http://localhost:9222/devtools/inspector.html?ws=localhost:62690
Plugin DevToolsPlugin registered.
Loading plugin GraphSelectGuidancePlugin from: C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\plugins\dev-proxy-plugins.dll
Registering plugin GraphSelectGuidancePlugin...
Plugin GraphSelectGuidancePlugin registered.
Loading plugin GraphBetaSupportGuidancePlugin from: C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\plugins\dev-proxy-plugins.dll
Registering plugin GraphBetaSupportGuidancePlugin...
Plugin GraphBetaSupportGuidancePlugin registered.
Loading plugin GraphConnectorGuidancePlugin from: C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\plugins\dev-proxy-plugins.dll
Registering plugin GraphConnectorGuidancePlugin...
Plugin GraphConnectorGuidancePlugin registered.
Loading plugin GraphSdkGuidancePlugin from: C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\plugins\dev-proxy-plugins.dll
Registering plugin GraphSdkGuidancePlugin...
Plugin GraphSdkGuidancePlugin registered.
Loading plugin ODataPagingGuidancePlugin from: C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\plugins\dev-proxy-plugins.dll
Registering plugin ODataPagingGuidancePlugin...
Plugin ODataPagingGuidancePlugin registered.
Loading plugin GraphClientRequestIdGuidancePlugin from: C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\plugins\dev-proxy-plugins.dll
Registering plugin GraphClientRequestIdGuidancePlugin...
Plugin GraphClientRequestIdGuidancePlugin registered.
Loading plugin GraphRandomErrorPlugin from: C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\plugins\dev-proxy-plugins.dll
Registering plugin GraphRandomErrorPlugin...
Plugin GraphRandomErrorPlugin registered.
Loading plugin ExecutionSummaryPlugin from: C:\Users\piotrkarpala\AppData\Local\Programs\Dev Proxy\plugins\dev-proxy-plugins.dll
Registering plugin ExecutionSummaryPlugin...
Plugin ExecutionSummaryPlugin registered.
Listening on 127.0.0.1:8000...
Set endpoint at Ip 127.0.0.1 and port: 8000 as System HTTP Proxy
Set endpoint at Ip 127.0.0.1 and port: 8000 as System HTTPS Proxy
Hotkeys: issue (w)eb request, (r)ecord, (s)top recording, (c)lear screen
Press CTRL+C to stop Dev Proxy

◉ Recording...
 request     GET https://graph.microsoft.com/v1.0/users
 warning   ╭ To help Microsoft investigate errors, to each request to Microsoft Graph
           │ add the client-request-id header with a unique GUID.
           │ More info at https://aka.ms/devproxy/guidance/client-request-id
           ╰ GET https://graph.microsoft.com/v1.0/users
@karpikpl karpikpl added the bug Something isn't working label May 8, 2024
@waldekmastykarz
Copy link
Collaborator

Thank you for reaching out @karpikpl and sorry to hear you're having trouble. Before starting Dev Proxy, have you closed all instances of Chrome (including all processes)? If there's a Chrome process active before you start Dev Proxy, Proxy won't be able to start Dev Tools with Chrome.

@karpikpl
Copy link
Contributor Author

I think that was it. I was expecting that even if the browser did not open - the service would still be there, listening on 9222.

Is there a way to capture this issue and throw an error?
I could PR it if you point me in the right direction :)

@waldekmastykarz
Copy link
Collaborator

Cool! We'd appreciate your help! Here, we're resolving browser to its x-plat process name:

return configuration.PreferredBrowser switch
{
PreferredBrowser.Chrome => RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\Google\Chrome\Application\chrome.exe")
: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
PreferredBrowser.EdgeDev => RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft\Edge Dev\Application\msedge.exe")
: "/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev",
_ => RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe")
: "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
};
.

We'd need to extend the InitInspector method (

private void InitInspector()
) to check for any instances of the process and show a warning when we find one. Let's keep in mind that the code we write for this needs to work at least on macOS and Windows.

@waldekmastykarz waldekmastykarz added enhancement New feature or request work in progress and removed bug Something isn't working labels May 13, 2024
@waldekmastykarz waldekmastykarz changed the title [BUG]: Can't connect to devtools Warn when browser is already running before starting DevTools May 13, 2024
karpikpl added a commit to karpikpl/dev-proxy that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request work in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants