Skip to content

Commit 0c2c433

Browse files
authored
Merge branch 'trunk' into js-bidi-permissions-module
2 parents d15c29b + dbf3dae commit 0c2c433

File tree

35 files changed

+1113
-320
lines changed

35 files changed

+1113
-320
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,47 @@ To automatically update and pin new dependencies, run:
210210

211211
### Python
212212

213-
You can run Python code locally by updating generated files in the python directory using:
213+
#### Linting
214+
215+
We follow the [PEP8 Style Guide for Python Code](https://peps.python.org/pep-0008) (except we use a 120 character line length).
216+
This is checked and enforced with several linting tools, including
217+
[black](https://pypi.org/project/black),
218+
[docformatter](https://pypi.org/project/docformatter),
219+
[flake8](https://flake8.pycqa.org),
220+
and [isort](https://pycqa.github.io/isort).
221+
222+
To run all of the linting tools:
214223
```shell
215-
./go py:update
224+
./go py:lint
216225
```
217226

218-
To install Selenium locally based on a specific commit, you can use:
227+
You need `tox` installed to run the linting tools (`pip install tox`).
228+
229+
#### Local Installation
230+
231+
To run Python code locally without building/installing the package, you must first install the dependencies:
232+
```shell
233+
pip install -r py/requirements.txt
234+
```
235+
236+
Then, build the generated files and copy them into your local source tree:
237+
```shell
238+
./go py:local_dev
239+
```
240+
241+
After that, you can import the selenium package directly from source from the `py` directory.
242+
243+
Instead of running from source, you can build and install the selenium package (wheel) locally:
219244
```shell
220245
./go py:install
221246
```
222247

248+
This will attempt to install into the global Python `site-packages` directory,
249+
which might not be writable. To avoid this, you should create and activate a
250+
[virtual environment](https://packaging.python.org/en/latest/tutorials/installing-packages/#creating-virtual-environments)
251+
before installing.
252+
253+
223254
### Ruby
224255

225256
Instead of using `irb`, you can create an interactive REPL with all gems loaded using: `bazel run //rb:console`

common/src/web/service-worker.js

Whitespace-only changes.

common/src/web/service_worker.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Service Worker Test Page</title>
5+
<script>
6+
if (navigator.serviceWorker) {
7+
navigator.serviceWorker.register("/service-worker.js", { scope: "/" })
8+
.then(() => navigator.serviceWorker.ready)
9+
.then(() => console.debug("[Companion]", "Service worker registered!"));
10+
}
11+
</script>
12+
</head>
13+
<body>
14+
<h1>This page loads a service worker</h1>
15+
</body>
16+
</html>

dotnet/src/webdriver/BiDi/BiDi.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
using System;
2121
using System.Threading.Tasks;
2222
using OpenQA.Selenium.BiDi.Communication;
23-
using OpenQA.Selenium.BiDi.Communication.Transport;
2423

2524
namespace OpenQA.Selenium.BiDi;
2625

2726
public class BiDi : IAsyncDisposable
2827
{
29-
private readonly ITransport _transport;
3028
private readonly Broker _broker;
3129

3230
private readonly Lazy<Modules.Session.SessionModule> _sessionModule;
@@ -42,8 +40,7 @@ internal BiDi(string url)
4240
{
4341
var uri = new Uri(url);
4442

45-
_transport = new WebSocketTransport(new Uri(url));
46-
_broker = new Broker(this, _transport);
43+
_broker = new Broker(this, uri);
4744

4845
_sessionModule = new Lazy<Modules.Session.SessionModule>(() => new Modules.Session.SessionModule(_broker));
4946
_browsingContextModule = new Lazy<Modules.BrowsingContext.BrowsingContextModule>(() => new Modules.BrowsingContext.BrowsingContextModule(_broker));
@@ -85,8 +82,12 @@ public Task EndAsync(Modules.Session.EndOptions? options = null)
8582

8683
public async ValueTask DisposeAsync()
8784
{
88-
await _broker.DisposeAsync().ConfigureAwait(false);
85+
await DisposeAsyncCore();
86+
GC.SuppressFinalize(this);
87+
}
8988

90-
_transport?.Dispose();
89+
protected virtual async ValueTask DisposeAsyncCore()
90+
{
91+
await _broker.DisposeAsync().ConfigureAwait(false);
9192
}
9293
}

dotnet/src/webdriver/BiDi/Communication/Broker.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,20 @@ public class Broker : IAsyncDisposable
5454

5555
private readonly BiDiJsonSerializerContext _jsonSerializerContext;
5656

57-
internal Broker(BiDi bidi, ITransport transport)
57+
internal Broker(BiDi bidi, Uri url)
5858
{
5959
_bidi = bidi;
60-
_transport = transport;
60+
_transport = new WebSocketTransport(url);
6161

6262
var jsonSerializerOptions = new JsonSerializerOptions
6363
{
6464
PropertyNameCaseInsensitive = true,
6565
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
6666
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
67+
68+
// BiDi returns special numbers such as "NaN" as strings
69+
// Additionally, -0 is returned as a string "-0"
70+
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals | JsonNumberHandling.AllowReadingFromString,
6771
Converters =
6872
{
6973
new BrowsingContextConverter(_bidi),
@@ -299,6 +303,12 @@ public async Task UnsubscribeAsync(Modules.Session.Subscription subscription, Ev
299303
}
300304

301305
public async ValueTask DisposeAsync()
306+
{
307+
await DisposeAsyncCore();
308+
GC.SuppressFinalize(this);
309+
}
310+
311+
protected virtual async ValueTask DisposeAsyncCore()
302312
{
303313
_pendingEvents.CompleteAdding();
304314

@@ -308,5 +318,7 @@ public async ValueTask DisposeAsync()
308318
{
309319
await _eventEmitterTask.ConfigureAwait(false);
310320
}
321+
322+
_transport.Dispose();
311323
}
312324
}

dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
3030
[JsonSerializable(typeof(Modules.Script.EvaluateResult.Success))]
3131
[JsonSerializable(typeof(Modules.Script.EvaluateResult.Exception))]
3232

33-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Number), TypeInfoPropertyName = "Script_RemoteValue_Number")]
34-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Boolean), TypeInfoPropertyName = "Script_RemoteValue_Boolean")]
35-
[JsonSerializable(typeof(Modules.Script.RemoteValue.String), TypeInfoPropertyName = "Script_RemoteValue_String")]
36-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Null), TypeInfoPropertyName = "Script_RemoteValue_Null")]
37-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Undefined), TypeInfoPropertyName = "Script_RemoteValue_Undefined")]
38-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Symbol))]
39-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Array), TypeInfoPropertyName = "Script_RemoteValue_Array")]
40-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Object), TypeInfoPropertyName = "Script_RemoteValue_Object")]
41-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Function))]
42-
[JsonSerializable(typeof(Modules.Script.RemoteValue.RegExp), TypeInfoPropertyName = "Script_RemoteValue_RegExp")]
43-
[JsonSerializable(typeof(Modules.Script.RemoteValue.RegExp.RegExpValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp_RegExpValue")]
44-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Date), TypeInfoPropertyName = "Script_RemoteValue_Date")]
45-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Map), TypeInfoPropertyName = "Script_RemoteValue_Map")]
46-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Set), TypeInfoPropertyName = "Script_RemoteValue_Set")]
47-
[JsonSerializable(typeof(Modules.Script.RemoteValue.WeakMap))]
48-
[JsonSerializable(typeof(Modules.Script.RemoteValue.WeakSet))]
49-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Generator))]
50-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Error))]
51-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Proxy))]
52-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Promise))]
53-
[JsonSerializable(typeof(Modules.Script.RemoteValue.TypedArray))]
54-
[JsonSerializable(typeof(Modules.Script.RemoteValue.ArrayBuffer))]
55-
[JsonSerializable(typeof(Modules.Script.RemoteValue.NodeList))]
56-
[JsonSerializable(typeof(Modules.Script.RemoteValue.HtmlCollection))]
57-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Node))]
58-
[JsonSerializable(typeof(Modules.Script.RemoteValue.WindowProxy))]
33+
[JsonSerializable(typeof(Modules.Script.NumberRemoteValue))]
34+
[JsonSerializable(typeof(Modules.Script.BooleanRemoteValue))]
35+
[JsonSerializable(typeof(Modules.Script.BigIntRemoteValue))]
36+
[JsonSerializable(typeof(Modules.Script.StringRemoteValue))]
37+
[JsonSerializable(typeof(Modules.Script.NullRemoteValue))]
38+
[JsonSerializable(typeof(Modules.Script.UndefinedRemoteValue))]
39+
[JsonSerializable(typeof(Modules.Script.SymbolRemoteValue))]
40+
[JsonSerializable(typeof(Modules.Script.ArrayRemoteValue))]
41+
[JsonSerializable(typeof(Modules.Script.ObjectRemoteValue))]
42+
[JsonSerializable(typeof(Modules.Script.FunctionRemoteValue))]
43+
[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue))]
44+
[JsonSerializable(typeof(Modules.Script.DateRemoteValue))]
45+
[JsonSerializable(typeof(Modules.Script.MapRemoteValue))]
46+
[JsonSerializable(typeof(Modules.Script.SetRemoteValue))]
47+
[JsonSerializable(typeof(Modules.Script.WeakMapRemoteValue))]
48+
[JsonSerializable(typeof(Modules.Script.WeakSetRemoteValue))]
49+
[JsonSerializable(typeof(Modules.Script.GeneratorRemoteValue))]
50+
[JsonSerializable(typeof(Modules.Script.ErrorRemoteValue))]
51+
[JsonSerializable(typeof(Modules.Script.ProxyRemoteValue))]
52+
[JsonSerializable(typeof(Modules.Script.PromiseRemoteValue))]
53+
[JsonSerializable(typeof(Modules.Script.TypedArrayRemoteValue))]
54+
[JsonSerializable(typeof(Modules.Script.ArrayBufferRemoteValue))]
55+
[JsonSerializable(typeof(Modules.Script.NodeListRemoteValue))]
56+
[JsonSerializable(typeof(Modules.Script.HtmlCollectionRemoteValue))]
57+
[JsonSerializable(typeof(Modules.Script.NodeRemoteValue))]
58+
[JsonSerializable(typeof(Modules.Script.WindowProxyRemoteValue))]
5959

6060
[JsonSerializable(typeof(Modules.Script.RealmInfo.Window))]
6161
[JsonSerializable(typeof(Modules.Script.RealmInfo.DedicatedWorker))]
@@ -140,8 +140,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
140140
[JsonSerializable(typeof(Modules.Network.FetchErrorEventArgs))]
141141
[JsonSerializable(typeof(Modules.Network.AuthRequiredEventArgs))]
142142

143-
[JsonSerializable(typeof(Modules.Script.Channel), TypeInfoPropertyName = "Script_Channel")]
144-
[JsonSerializable(typeof(Modules.Script.LocalValue.String), TypeInfoPropertyName = "Script_LocalValue_String")]
145143
[JsonSerializable(typeof(Modules.Script.Target.Realm), TypeInfoPropertyName = "Script_Target_Realm")]
146144
[JsonSerializable(typeof(Modules.Script.Target.Context), TypeInfoPropertyName = "Script_Target_Context")]
147145

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal class LocateNodesResultConverter : JsonConverter<LocateNodesResult>
3131
public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3232
{
3333
using var doc = JsonDocument.ParseValue(ref reader);
34-
var nodes = doc.RootElement.GetProperty("nodes").Deserialize<IReadOnlyList<RemoteValue.Node>>(options);
34+
var nodes = doc.RootElement.GetProperty("nodes").Deserialize<IReadOnlyList<NodeRemoteValue>>(options);
3535

3636
return new LocateNodesResult(nodes!);
3737
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,37 @@ internal class RemoteValueConverter : JsonConverter<RemoteValue>
3333

3434
if (jsonDocument.RootElement.ValueKind == JsonValueKind.String)
3535
{
36-
return new RemoteValue.String(jsonDocument.RootElement.GetString()!);
36+
return new StringRemoteValue(jsonDocument.RootElement.GetString()!);
3737
}
3838

3939
return jsonDocument.RootElement.GetProperty("type").ToString() switch
4040
{
41-
"number" => jsonDocument.Deserialize<RemoteValue.Number>(options),
42-
"boolean" => jsonDocument.Deserialize<RemoteValue.Boolean>(options),
43-
"string" => jsonDocument.Deserialize<RemoteValue.String>(options),
44-
"null" => jsonDocument.Deserialize<RemoteValue.Null>(options),
45-
"undefined" => jsonDocument.Deserialize<RemoteValue.Undefined>(options),
46-
"symbol" => jsonDocument.Deserialize<RemoteValue.Symbol>(options),
47-
"array" => jsonDocument.Deserialize<RemoteValue.Array>(options),
48-
"object" => jsonDocument.Deserialize<RemoteValue.Object>(options),
49-
"function" => jsonDocument.Deserialize<RemoteValue.Function>(options),
50-
"regexp" => jsonDocument.Deserialize<RemoteValue.RegExp>(options),
51-
"date" => jsonDocument.Deserialize<RemoteValue.Date>(options),
52-
"map" => jsonDocument.Deserialize<RemoteValue.Map>(options),
53-
"set" => jsonDocument.Deserialize<RemoteValue.Set>(options),
54-
"weakmap" => jsonDocument.Deserialize<RemoteValue.WeakMap>(options),
55-
"weakset" => jsonDocument.Deserialize<RemoteValue.WeakSet>(options),
56-
"generator" => jsonDocument.Deserialize<RemoteValue.Generator>(options),
57-
"error" => jsonDocument.Deserialize<RemoteValue.Error>(options),
58-
"proxy" => jsonDocument.Deserialize<RemoteValue.Proxy>(options),
59-
"promise" => jsonDocument.Deserialize<RemoteValue.Promise>(options),
60-
"typedarray" => jsonDocument.Deserialize<RemoteValue.TypedArray>(options),
61-
"arraybuffer" => jsonDocument.Deserialize<RemoteValue.ArrayBuffer>(options),
62-
"nodelist" => jsonDocument.Deserialize<RemoteValue.NodeList>(options),
63-
"htmlcollection" => jsonDocument.Deserialize<RemoteValue.HtmlCollection>(options),
64-
"node" => jsonDocument.Deserialize<RemoteValue.Node>(options),
65-
"window" => jsonDocument.Deserialize<RemoteValue.WindowProxy>(options),
41+
"number" => jsonDocument.Deserialize<NumberRemoteValue>(options),
42+
"boolean" => jsonDocument.Deserialize<BooleanRemoteValue>(options),
43+
"bigint" => jsonDocument.Deserialize<BigIntRemoteValue>(options),
44+
"string" => jsonDocument.Deserialize<StringRemoteValue>(options),
45+
"null" => jsonDocument.Deserialize<NullRemoteValue>(options),
46+
"undefined" => jsonDocument.Deserialize<UndefinedRemoteValue>(options),
47+
"symbol" => jsonDocument.Deserialize<SymbolRemoteValue>(options),
48+
"array" => jsonDocument.Deserialize<ArrayRemoteValue>(options),
49+
"object" => jsonDocument.Deserialize<ObjectRemoteValue>(options),
50+
"function" => jsonDocument.Deserialize<FunctionRemoteValue>(options),
51+
"regexp" => jsonDocument.Deserialize<RegExpRemoteValue>(options),
52+
"date" => jsonDocument.Deserialize<DateRemoteValue>(options),
53+
"map" => jsonDocument.Deserialize<MapRemoteValue>(options),
54+
"set" => jsonDocument.Deserialize<SetRemoteValue>(options),
55+
"weakmap" => jsonDocument.Deserialize<WeakMapRemoteValue>(options),
56+
"weakset" => jsonDocument.Deserialize<WeakSetRemoteValue>(options),
57+
"generator" => jsonDocument.Deserialize<GeneratorRemoteValue>(options),
58+
"error" => jsonDocument.Deserialize<ErrorRemoteValue>(options),
59+
"proxy" => jsonDocument.Deserialize<ProxyRemoteValue>(options),
60+
"promise" => jsonDocument.Deserialize<PromiseRemoteValue>(options),
61+
"typedarray" => jsonDocument.Deserialize<TypedArrayRemoteValue>(options),
62+
"arraybuffer" => jsonDocument.Deserialize<ArrayBufferRemoteValue>(options),
63+
"nodelist" => jsonDocument.Deserialize<NodeListRemoteValue>(options),
64+
"htmlcollection" => jsonDocument.Deserialize<HtmlCollectionRemoteValue>(options),
65+
"node" => jsonDocument.Deserialize<NodeRemoteValue>(options),
66+
"window" => jsonDocument.Deserialize<WindowProxyRemoteValue>(options),
6667
_ => null,
6768
};
6869
}

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ public record LocateNodesOptions : CommandOptions
3737
public IEnumerable<Script.ISharedReference>? StartNodes { get; set; }
3838
}
3939

40-
public record LocateNodesResult : IReadOnlyList<Script.RemoteValue.Node>
40+
public record LocateNodesResult : IReadOnlyList<Script.NodeRemoteValue>
4141
{
42-
private readonly IReadOnlyList<Script.RemoteValue.Node> _nodes;
42+
private readonly IReadOnlyList<Script.NodeRemoteValue> _nodes;
4343

44-
internal LocateNodesResult(IReadOnlyList<Script.RemoteValue.Node> nodes)
44+
internal LocateNodesResult(IReadOnlyList<Script.NodeRemoteValue> nodes)
4545
{
4646
_nodes = nodes;
4747
}
4848

49-
public Script.RemoteValue.Node this[int index] => _nodes[index];
49+
public Script.NodeRemoteValue this[int index] => _nodes[index];
5050

5151
public int Count => _nodes.Count;
5252

53-
public IEnumerator<Script.RemoteValue.Node> GetEnumerator() => _nodes.GetEnumerator();
53+
public IEnumerator<Script.NodeRemoteValue> GetEnumerator() => _nodes.GetEnumerator();
5454

5555
IEnumerator IEnumerable.GetEnumerator() => (_nodes as IEnumerable).GetEnumerator();
5656
}

dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace OpenQA.Selenium.BiDi.Modules.Script;
2525
internal class AddPreloadScriptCommand(AddPreloadScriptCommandParameters @params)
2626
: Command<AddPreloadScriptCommandParameters>(@params, "script.addPreloadScript");
2727

28-
internal record AddPreloadScriptCommandParameters(string FunctionDeclaration, IEnumerable<LocalValue.Channel>? Arguments, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, string? Sandbox) : CommandParameters;
28+
internal record AddPreloadScriptCommandParameters(string FunctionDeclaration, IEnumerable<ChannelLocalValue>? Arguments, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, string? Sandbox) : CommandParameters;
2929

3030
public record AddPreloadScriptOptions : CommandOptions
3131
{
@@ -37,7 +37,7 @@ internal AddPreloadScriptOptions(BrowsingContextAddPreloadScriptOptions? options
3737
Sandbox = options?.Sandbox;
3838
}
3939

40-
public IEnumerable<LocalValue.Channel>? Arguments { get; set; }
40+
public IEnumerable<ChannelLocalValue>? Arguments { get; set; }
4141

4242
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
4343

@@ -46,7 +46,7 @@ internal AddPreloadScriptOptions(BrowsingContextAddPreloadScriptOptions? options
4646

4747
public record BrowsingContextAddPreloadScriptOptions
4848
{
49-
public IEnumerable<LocalValue.Channel>? Arguments { get; set; }
49+
public IEnumerable<ChannelLocalValue>? Arguments { get; set; }
5050

5151
public string? Sandbox { get; set; }
5252
}

0 commit comments

Comments
 (0)