-
-
Notifications
You must be signed in to change notification settings - Fork 484
Expand file tree
/
Copy pathBidiElementHandle.cs
More file actions
131 lines (107 loc) · 4.61 KB
/
Copy pathBidiElementHandle.cs
File metadata and controls
131 lines (107 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// * MIT License
// *
// * Copyright (c) Darío Kondratiuk
// *
// * Permission is hereby granted, free of charge, to any person obtaining a copy
// * of this software and associated documentation files (the "Software"), to deal
// * in the Software without restriction, including without limitation the rights
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// * copies of the Software, and to permit persons to whom the Software is
// * furnished to do so, subject to the following conditions:
// *
// * The above copyright notice and this permission notice shall be included in all
// * copies or substantial portions of the Software.
// *
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// * SOFTWARE.
#if !CDP_ONLY
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using PuppeteerSharp.QueryHandlers;
using WebDriverBiDi.BrowsingContext;
using WebDriverBiDi.Script;
namespace PuppeteerSharp.Bidi;
#pragma warning disable CA2000
internal class BidiElementHandle(RemoteValue value, BidiRealm realm) : ElementHandle(BidiJSHandle.From(value, realm))
#pragma warning restore CA2000
{
/// <summary>
/// Bidi Remote value.
/// </summary>
public RemoteValue Value { get; } = value;
internal BidiJSHandle BidiJSHandle => Handle as BidiJSHandle;
internal override Realm Realm => realm;
internal override CustomQuerySelectorRegistry CustomQuerySelectorRegistry => CustomQuerySelectorRegistry.Default;
internal BidiFrame BidiFrame => realm.Environment as BidiFrame;
protected override Page Page => BidiFrame.BidiPage;
public static IJSHandle From(RemoteValue value, BidiRealm realm)
{
return new BidiElementHandle(value, realm);
}
public override async Task UploadFileAsync(bool resolveFilePaths, params string[] filePaths)
{
// Resolve file paths to absolute paths if needed
if (resolveFilePaths)
{
filePaths = filePaths.Select(file =>
{
if (Path.IsPathRooted(file))
{
return file;
}
return Path.GetFullPath(file);
}).ToArray();
}
await BidiFrame.SetFilesAsync(this, filePaths).ConfigureAwait(false);
}
public override async Task<IFrame> ContentFrameAsync()
{
var handle = await EvaluateFunctionHandleAsync(@"element => {
if (element instanceof HTMLIFrameElement || element instanceof HTMLFrameElement) {
return element.contentWindow;
}
return;
}").ConfigureAwait(false);
// Get the RemoteValue from either BidiJSHandle or BidiElementHandle (which wraps BidiJSHandle)
RemoteValue value = handle switch
{
BidiElementHandle bidiElement => bidiElement.BidiJSHandle.RemoteValue,
BidiJSHandle bidiJsHandle => bidiJsHandle.RemoteValue,
_ => null,
};
await handle.DisposeAsync().ConfigureAwait(false);
if (value?.Type == "window" && value.Value is WindowProxyProperties windowProxy)
{
var contextId = windowProxy.Context;
return BidiFrame.BidiPage.Frames.FirstOrDefault(frame => frame.Id == contextId);
}
return null;
}
public override Task<int> BackendNodeIdAsync()
{
if (!BidiFrame.BidiPage.BidiBrowser.CdpSupported)
{
throw new PuppeteerException("BackendNodeId is not supported in the current configuration.");
}
throw new PuppeteerException("BackendNodeId is not supported in the current configuration.");
}
public override Task AutofillAsync(AutofillData data)
=> throw new PuppeteerException("Autofill is not supported in the current configuration.");
internal async IAsyncEnumerable<IElementHandle> QueryAXTreeAsync(string name, string role)
{
var locator = new AccessibilityLocator { Name = name, Role = role };
var results = await BidiFrame.LocateNodesAsync(this, locator).ConfigureAwait(false);
foreach (var node in results)
{
yield return new BidiElementHandle(node, realm);
}
}
}
#endif