Skip to content

Commit

Permalink
Improved PR #168
Browse files Browse the repository at this point in the history
  • Loading branch information
openbullet committed Mar 26, 2021
1 parent 1638583 commit eba187d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
3 changes: 3 additions & 0 deletions OpenBullet2/Resources/Pages/EditSettings.it.resx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@
<data name="Invert" xml:space="preserve">
<value>Inverti</value>
</data>
<data name="LoadOnlyDocumentAndScript" xml:space="preserve">
<value>Carica solo documento e script</value>
</data>
<data name="MaxUsesPerProxy" xml:space="preserve">
<value>Massimi utilizzi per singolo proxy (0 è infinito)</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions OpenBullet2/Resources/Pages/EditSettings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@
<data name="Invert" xml:space="preserve">
<value>Invert</value>
</data>
<data name="LoadOnlyDocumentAndScript" xml:space="preserve">
<value>Load only document and script</value>
</data>
<data name="MaxUsesPerProxy" xml:space="preserve">
<value>Maximum uses per proxy (0 is infinite)</value>
</data>
Expand Down
39 changes: 22 additions & 17 deletions RuriLib/Blocks/Puppeteer/Browser/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public static async Task PuppeteerOpenBrowser(BotData data)
data.Objects["puppeteer"] = browser;
var page = (await browser.PagesAsync()).First();
SetPageAndFrame(data, page);
await SetPageLoadingOptions(data, page);

// Authenticate if the proxy requires auth
if(data.UseProxy && data.Proxy is { NeedsAuthentication: true, Type: ProxyType.Http } proxy)
if (data.UseProxy && data.Proxy is { NeedsAuthentication: true, Type: ProxyType.Http } proxy)
await page.AuthenticateAsync(new Credentials { Username = proxy.Username, Password = proxy.Password });

data.Logger.Log($"{(launchOptions.Headless ? "Headless " : "")}Browser opened successfully!", LogColors.DarkSalmon);
Expand All @@ -95,22 +96,7 @@ public static async Task PuppeteerNewTab(BotData data)

var browser = GetBrowser(data);
var page = await browser.NewPageAsync();

if (data.ConfigSettings.PuppeteerSettings.LoadOnlyDocumentAndScript)
{
await page.SetRequestInterceptionAsync(true);
page.Request += (sender, e) =>
{
if (e.Request.ResourceType == ResourceType.Document || e.Request.ResourceType == ResourceType.Script)
{
e.Request.ContinueAsync();
}
else
{
e.Request.AbortAsync();
}
};
}
await SetPageLoadingOptions(data, page);

SetPageAndFrame(data, page); // Set the new page as active
data.Logger.Log($"Opened a new page", LogColors.DarkSalmon);
Expand Down Expand Up @@ -208,5 +194,24 @@ private static void StopYoveProxyInternalServer(BotData data)
proxyClient.Dispose();
}
}

private static async Task SetPageLoadingOptions(BotData data, PuppeteerSharp.Page page)
{
if (data.ConfigSettings.PuppeteerSettings.LoadOnlyDocumentAndScript)
{
await page.SetRequestInterceptionAsync(true);
page.Request += (sender, e) =>
{
if (e.Request.ResourceType == ResourceType.Document || e.Request.ResourceType == ResourceType.Script)
{
e.Request.ContinueAsync();
}
else
{
e.Request.AbortAsync();
}
};
}
}
}
}

0 comments on commit eba187d

Please sign in to comment.