Update Emulator for Ngrok v3 Support
Fixes #2389
Version 3.x of Ngrok makes changes to the config file format and the supported command line arguments. The path field has been removed from the arguments, while the region field has been moved to the config file (where it is now required rather than optional). This causes the existing version of Emulator to fail when attempting to spawn Ngrok and connect to a remote bot.
This PR updates ngrok.ts and ngrokService.ts to remove the path and region fields so they are not passed to the Ngrok instance, thereby allowing Ngrok v3 to be used with Emulator.
Specific Changes:
- Remove path and region from from
NgrokOptions. - Update
ngrokService.tsto pass the path to thengrok.tsconstructor when creating the Ngrok instance instead of passing it as an argument to the instance. - Update
ngrok.tsto use the path passed into the constructor instead of the path fromNgrokOptions.
@anishprasad01 thank you for the contribution! would this break using Emulator with ngrok v2?
@cwhitten,
I attempted to run with Ngrok v2.3.40 and was successfully able to connect to a bot hosted in Azure. Since the region field was optional in Ngrok v2, its presence should not break anything. I will perform further testing before this PR gets merged.
coverage: 66.953% (-0.7%) from 67.69% when pulling 3489b62f066f6fe997224f6cac6b2a3a7268829c on anishprasad01/ngrok-v3-fix into d144dd22074134ffc66ee981d3d203aa6ec6beda on main.
Testing with both Ngrok v2 and v3 reveals that v2 remains supported even with the modifications made to support v3. Communication with an Azure bot is successful and no errors appear when running or exiting the application. A search of running processes after exiting the application reveals that the Ngrok process is terminated successfully.
Testing with v2:

Testing with v3:

hi! PM for ngrok here. I'd love to see this PR merged so that we could move your users to the latest version of the ngrok agent. If I can help in any way, please let me know.
/AzurePipelines run
Azure Pipelines successfully started running 1 pipeline(s).
Build is failing due to the test failures:
FAIL packages/app/main/src/ngrok.spec.ts
● the ngrok › ngrok connect/disconnect operations › should throw if it failed to find an ngrok executable at the specified path.
expect(received).toBe(expected) // Object.is equality
Expected: "Error: Could not find ngrok executable at path: Applications\\ngrok. Make sure that the correct path to ngrok is configured in the Emulator app settings. Ngrok is required to receive a token from the Bot Framework token service."
Received: "Error: Could not find ngrok executable at path: D:\\a\\1\\s\\packages\\app\\main\\src\\bin\\ngrok.exe. Make sure that the correct path to ngrok is configured in the Emulator app settings. Ngrok is required to receive a token from the Bot Framework token service."
225 | thrown = e;
226 | }
> 227 | expect(thrown.toString()).toBe(
| ^
228 | `Error: Could not find ngrok executable at path: ${path}. Make sure that the correct path to ngrok is configured in the Emulator app settings. Ngrok is required to receive a token from the Bot Framework token service.`
229 | );
230 | });
Build is failing due to the test failures:
FAIL packages/app/main/src/ngrok.spec.ts ● the ngrok › ngrok connect/disconnect operations › should throw if it failed to find an ngrok executable at the specified path. expect(received).toBe(expected) // Object.is equality Expected: "Error: Could not find ngrok executable at path: Applications\\ngrok. Make sure that the correct path to ngrok is configured in the Emulator app settings. Ngrok is required to receive a token from the Bot Framework token service." Received: "Error: Could not find ngrok executable at path: D:\\a\\1\\s\\packages\\app\\main\\src\\bin\\ngrok.exe. Make sure that the correct path to ngrok is configured in the Emulator app settings. Ngrok is required to receive a token from the Bot Framework token service." 225 | thrown = e; 226 | } > 227 | expect(thrown.toString()).toBe( | ^ 228 | `Error: Could not find ngrok executable at path: ${path}. Make sure that the correct path to ngrok is configured in the Emulator app settings. Ngrok is required to receive a token from the Bot Framework token service.` 229 | ); 230 | });
Any update on this? Unfortunately it seems ngrok v2 is not usable anymore and Emulator is not working with any version of Ngrok v3. So, at the moment, it is not possible to contact a remote bot with Emulator.