Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Enabled puppeteer connections to work, so haky
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdeafcafe committed Apr 27, 2020
1 parent 456690f commit 4743471
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions dotnet/Global/Libraries/JsonClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public JsonClient(string baseUrl, HttpClientOptions options = null)
Client = new HttpClient(baseUrl, options);
}

public async Task<TRes> Do<TRes>(string verb, string path, HttpClientOptions newOpts = null)
where TRes : class
{
return await Do<TRes>(verb, path, null, null, newOpts);
}

public async Task<TRes> Do<TRes>(string verb, string path, Dictionary<string, string> query = null, HttpClientOptions newOpts = null)
where TRes : class
{
Expand Down
21 changes: 19 additions & 2 deletions dotnet/Global/Services/ChromieTalkie.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,7 +24,7 @@ public class Config
public ChromieTalkie(ILoggerFactory loggerFactory, IOptionsMonitor<Config> options)
{
_logger = loggerFactory.CreateLogger(typeof(ChromieTalkie));
_config = options.Get("RemoteEndpoint");
_config = options.CurrentValue;

if (_config.RemoteEndpoint == null)
{
Expand All @@ -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<string, string> { { "Host", "" } } };
var meta = await chromeClient.Do<ChromeInstanceMeta>("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; }
}
}
}
8 changes: 6 additions & 2 deletions dotnet/Services/Token/Models/Config.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Branch.Global.Libraries;
using Branch.Global.Services;

namespace Branch.Services.Token.Models
{
public class Config
{
public string[] InternalKeys { get; set; }

public string RemotePuppeteerEndpoint { get; set; }
public ChromieTalkie.Config Puppeteer { get; set; }

public ConfigAuthProviders AuthProviders { get; set; }

Expand All @@ -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
{
Expand Down

0 comments on commit 4743471

Please sign in to comment.