diff --git a/dotnet/Global/Libraries/JsonClient.cs b/dotnet/Global/Libraries/JsonClient.cs index e938de26..42ba17cf 100644 --- a/dotnet/Global/Libraries/JsonClient.cs +++ b/dotnet/Global/Libraries/JsonClient.cs @@ -32,6 +32,12 @@ public JsonClient(string baseUrl, HttpClientOptions options = null) Client = new HttpClient(baseUrl, options); } + public async Task Do(string verb, string path, HttpClientOptions newOpts = null) + where TRes : class + { + return await Do(verb, path, null, null, newOpts); + } + public async Task Do(string verb, string path, Dictionary query = null, HttpClientOptions newOpts = null) where TRes : class { diff --git a/dotnet/Global/Services/ChromieTalkie.cs b/dotnet/Global/Services/ChromieTalkie.cs index 46af6313..cbb8db98 100644 --- a/dotnet/Global/Services/ChromieTalkie.cs +++ b/dotnet/Global/Services/ChromieTalkie.cs @@ -1,7 +1,11 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using Branch.Global.Libraries; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Newtonsoft.Json; using PuppeteerSharp; namespace Branch.Global.Services @@ -20,7 +24,7 @@ public class Config public ChromieTalkie(ILoggerFactory loggerFactory, IOptionsMonitor options) { _logger = loggerFactory.CreateLogger(typeof(ChromieTalkie)); - _config = options.Get("RemoteEndpoint"); + _config = options.CurrentValue; if (_config.RemoteEndpoint == null) { @@ -43,12 +47,25 @@ private async Task EnsureBrowserReady() return; } - Browser = await Puppeteer.ConnectAsync(new ConnectOptions { BrowserWSEndpoint = _config.RemoteEndpoint }); + var chromeClient = new JsonClient($"http://{_config.RemoteEndpoint}"); + var options = new HttpClientOptions { Headers = new Dictionary { { "Host", "" } } }; + var meta = await chromeClient.Do("GET", "/json/version", options); + var url = meta.WebSocketDebuggerUrl; + var id = url.Split("/").Last(); + var finalRemoteUrl = $"ws://{_config.RemoteEndpoint}/devtools/browser/{id}"; + + Browser = await Puppeteer.ConnectAsync(new ConnectOptions { BrowserWSEndpoint = finalRemoteUrl }); } public void Dispose() { Browser?.Dispose(); } + + private class ChromeInstanceMeta + { + [JsonProperty("webSocketDebuggerUrl")] + public string WebSocketDebuggerUrl { get; set; } + } } } diff --git a/dotnet/Services/Token/Models/Config.cs b/dotnet/Services/Token/Models/Config.cs index 878f2480..517bddca 100644 --- a/dotnet/Services/Token/Models/Config.cs +++ b/dotnet/Services/Token/Models/Config.cs @@ -1,4 +1,5 @@ using Branch.Global.Libraries; +using Branch.Global.Services; namespace Branch.Services.Token.Models { @@ -6,7 +7,7 @@ public class Config { public string[] InternalKeys { get; set; } - public string RemotePuppeteerEndpoint { get; set; } + public ChromieTalkie.Config Puppeteer { get; set; } public ConfigAuthProviders AuthProviders { get; set; } @@ -17,7 +18,10 @@ public static Config CreateDefault() return new Config { InternalKeys = new string[] {"test"}, - RemotePuppeteerEndpoint = null, + Puppeteer = new ChromieTalkie.Config + { + RemoteEndpoint = "ws://rancher.forbes.red:6969", + }, RedisConnectionString = "redis://127.0.0.1:6379?db=0", AuthProviders = new ConfigAuthProviders {