Skip to content

Commit 4bf7716

Browse files
authored
Remove unused code (#2296)
* Remove unused code * go a few versions back * Fix dispose code * fancy stuff
1 parent 588c439 commit 4bf7716

File tree

7 files changed

+16
-84
lines changed

7 files changed

+16
-84
lines changed

lib/.editorconfig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,13 @@ dotnet_diagnostic.CA1303.severity = none
322322
# IL3000: Avoid accessing Assembly file path when publishing as a single file
323323
dotnet_diagnostic.IL3000.severity = none
324324

325-
# C++ Files
325+
# C++ Files
326+
327+
# Default severity for analyzer diagnostics with category 'Usage'
328+
dotnet_analyzer_diagnostic.category-Usage.severity = none
326329

327-
# Default severity for analyzer diagnostics with category 'Usage'
328-
dotnet_analyzer_diagnostic.category-Usage.severity = none
330+
# Default severity for analyzer diagnostics with category 'CodeQuality'
331+
dotnet_analyzer_diagnostic.category-CodeQuality.severity = error
329332

330333
[*.{cpp,h,in}]
331334
curly_bracket_next_line = true

lib/PuppeteerSharp/Browser.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public class Browser : IBrowser
2525
private readonly Func<TargetInfo, bool> _isPageTargetFunc;
2626
private readonly BrowserContext _defaultContext;
2727
private readonly CustomQueriesManager _customQueriesManager = new();
28-
private readonly Func<Task> _closeCallback;
2928
private Task _closeTask;
3029

3130
internal Browser(
@@ -35,15 +34,13 @@ internal Browser(
3534
bool ignoreHTTPSErrors,
3635
ViewPortOptions defaultViewport,
3736
LauncherBase launcher,
38-
Func<Task> closeCallback = null,
3937
Func<TargetInfo, bool> targetFilter = null,
4038
Func<TargetInfo, bool> isPageTargetFunc = null)
4139
{
4240
IgnoreHTTPSErrors = ignoreHTTPSErrors;
4341
DefaultViewport = defaultViewport;
4442
Launcher = launcher;
4543
Connection = connection;
46-
_closeCallback = closeCallback;
4744
_targetFilterCallback = targetFilter ?? ((TargetInfo _) => true);
4845
_logger = Connection.LoggerFactory.CreateLogger<Browser>();
4946
_isPageTargetFunc =
@@ -271,7 +268,6 @@ internal static async Task<Browser> CreateAsync(
271268
bool ignoreHTTPSErrors,
272269
ViewPortOptions defaultViewPort,
273270
LauncherBase launcher,
274-
Func<Task> closeCallback = null,
275271
Func<TargetInfo, bool> targetFilter = null,
276272
Func<TargetInfo, bool> isPageTargetCallback = null,
277273
Action<IBrowser> initAction = null)
@@ -283,7 +279,6 @@ internal static async Task<Browser> CreateAsync(
283279
ignoreHTTPSErrors,
284280
defaultViewPort,
285281
launcher,
286-
closeCallback,
287282
targetFilter,
288283
isPageTargetCallback);
289284

lib/PuppeteerSharp/BrowserFetcher.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,25 +263,6 @@ private static void ExtractTar(string zipPath, string folderPath)
263263
process.WaitForExit();
264264
}
265265

266-
private string GetFolderPath(string revision)
267-
=> Path.Combine(CacheDir, $"{Platform}-{revision}");
268-
269-
private void NativeExtractToDirectory(string zipPath, string folderPath)
270-
{
271-
var destinationDirectoryInfo = new DirectoryInfo(folderPath);
272-
273-
if (!destinationDirectoryInfo.Exists)
274-
{
275-
destinationDirectoryInfo.Create();
276-
}
277-
278-
using var process = new Process();
279-
process.StartInfo.FileName = "unzip";
280-
process.StartInfo.Arguments = $"\"{zipPath}\" -d \"{folderPath}\"";
281-
process.Start();
282-
process.WaitForExit();
283-
}
284-
285266
private Task InstallDMGAsync(string dmgPath, string folderPath)
286267
{
287268
try

lib/PuppeteerSharp/IsolatedWorld.cs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -498,60 +498,5 @@ private async Task OnBindingCalledAsync(BindingCalledResponse e)
498498
_logger.LogError(ex.ToString());
499499
}
500500
}
501-
502-
private async Task<IElementHandle> WaitForSelectorAsync(string selectorOrXPath, bool isXPath, WaitForSelectorOptions options = null)
503-
{
504-
options ??= new WaitForSelectorOptions();
505-
var waitForVisible = options?.Visible ?? false;
506-
var waitForHidden = options?.Hidden ?? false;
507-
var timeout = options.Timeout ?? _timeoutSettings.Timeout;
508-
509-
const string predicate = @"function predicate(selectorOrXPath, isXPath, waitForVisible, waitForHidden) {
510-
const node = isXPath
511-
? document.evaluate(selectorOrXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
512-
: document.querySelector(selectorOrXPath);
513-
if (!node)
514-
return waitForHidden;
515-
if (!waitForVisible && !waitForHidden)
516-
return node;
517-
const element = node.nodeType === Node.TEXT_NODE ? node.parentElement : node;
518-
519-
const style = window.getComputedStyle(element);
520-
const isVisible = style && style.visibility !== 'hidden' && hasVisibleBoundingBox();
521-
const success = (waitForVisible === isVisible || waitForHidden === !isVisible);
522-
return success ? node : null;
523-
524-
function hasVisibleBoundingBox() {
525-
const rect = element.getBoundingClientRect();
526-
return !!(rect.top || rect.bottom || rect.width || rect.height);
527-
}
528-
}";
529-
var polling = waitForVisible || waitForHidden ? WaitForFunctionPollingOption.Raf : WaitForFunctionPollingOption.Mutation;
530-
531-
using var waitTask = new WaitTask(
532-
this,
533-
predicate,
534-
false,
535-
polling,
536-
null, // Polling interval
537-
timeout,
538-
options.Root,
539-
null,
540-
new object[] { selectorOrXPath, isXPath, options.Visible, options.Hidden });
541-
542-
var handle = await waitTask.Task.ConfigureAwait(false);
543-
544-
if (handle is not IElementHandle elementHandle)
545-
{
546-
if (handle != null)
547-
{
548-
await handle.DisposeAsync().ConfigureAwait(false);
549-
}
550-
551-
return null;
552-
}
553-
554-
return elementHandle;
555-
}
556501
}
557502
}

lib/PuppeteerSharp/Launcher.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public async Task<IBrowser> ConnectAsync(ConnectOptions options)
143143
options.IgnoreHTTPSErrors,
144144
options.DefaultViewport,
145145
null,
146-
null,
147146
options.TargetFilter,
148147
null,
149148
options.InitAction)

lib/PuppeteerSharp/PuppeteerSharp.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
3333
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" />
3434
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
35-
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
35+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507">
3636
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3737
<PrivateAssets>all</PrivateAssets>
3838
</PackageReference>
@@ -49,6 +49,10 @@
4949
<PrivateAssets>all</PrivateAssets>
5050
</PackageReference>
5151
<PackageReference Include="System.Text.Encodings.Web" Version="6.0.0" />
52+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.3.1">
53+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
54+
<PrivateAssets>all</PrivateAssets>
55+
</PackageReference>
5256
</ItemGroup>
5357
<ItemGroup>
5458
<AdditionalFiles Include="..\stylecop.json" Link="stylecop.json" />

lib/PuppeteerSharp/WaitTask.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public void Dispose()
7979
return;
8080
}
8181

82+
if (_timeoutTimer is { Status: TaskStatus.RanToCompletion or TaskStatus.Faulted or TaskStatus.Canceled } timeoutTimer)
83+
{
84+
timeoutTimer.Dispose();
85+
}
86+
8287
_cts.Dispose();
8388

8489
_isDisposed = true;

0 commit comments

Comments
 (0)