You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Introduced a new method GetTreeAsync in the BrowsingContext class to retrieve the browsing context tree with the current context set as the root by default.
Updated intercept and preload script methods to use specific options classes (BrowsingContextAddInterceptOptions and BrowsingContextAddPreloadScriptOptions) to ensure context is set correctly.
Added new options classes (BrowsingContextGetTreeOptions, BrowsingContextAddInterceptOptions, BrowsingContextAddPreloadScriptOptions) with internal properties to encapsulate context-specific configurations.
Changes walkthrough 📝
Relevant files
Enhancement
BrowsingContext.cs
Add `GetTreeAsync` method to BrowsingContext class
Possible Null Reference The GetTreeAsync method uses the null-coalescing operator to create a new BrowsingContextGetTreeOptions if options is null, but then immediately accesses options.Root without checking for null. This could potentially lead to a null reference exception if BrowsingContextGetTreeOptions is implemented to allow Root to be null.
Inconsistent Naming The method parameters use BrowsingContextAddInterceptOptions, but the local variable is still named interceptOptions. Consider renaming the local variable to match the new type name for consistency.
public Task<IReadOnlyList<BrowsingContextInfo>> GetTreeAsync(BrowsingContextGetTreeOptions? options = null)
{
options ??= new();
options.Root = this;
+ if (_bidi?.BrowsingContextModule == null)+ {+ throw new InvalidOperationException("BrowsingContextModule is not initialized.");+ }+
return _bidi.BrowsingContextModule.GetTreeAsync(options);
}
Apply this suggestion
Suggestion importance[1-10]: 9
Why: Adding null checks for _bidi and _bidi.BrowsingContextModule is a crucial improvement to prevent potential null reference exceptions, which could lead to runtime errors. This suggestion enhances the robustness of the code.
9
Best practice
Improve encapsulation by making the property setter private and providing an internal method for setting the value
Consider making the Root property in BrowsingContextGetTreeOptions private set instead of internal to improve encapsulation.
public record BrowsingContextGetTreeOptions : GetTreeOptions
{
- internal new BrowsingContext? Root+ public new BrowsingContext? Root
{
get => base.Root;
- set => base.Root = value;+ private set => base.Root = value;
}
++ internal void SetRoot(BrowsingContext? root) => Root = root;
}
Apply this suggestion
Suggestion importance[1-10]: 8
Why: Making the Root property setter private and providing an internal method for setting the value improves encapsulation, which is a best practice for maintaining control over how properties are modified.
8
Enhancement
Use null-coalescing assignment operator for simplification and to prevent overwriting existing values
Consider using the null-coalescing assignment operator ??= for interceptOptions.Contexts to simplify the code and ensure it's not overwritten if already set.
Why: The suggestion to use the null-coalescing assignment operator simplifies the code and ensures that existing values are not overwritten, improving code readability and maintainability.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Description
New method
which is equivalent to:
Motivation and Context
One more method forwarding options implicitly depending on current context.
Types of changes
Checklist
PR Type
Enhancement
Description
GetTreeAsync
in theBrowsingContext
class to retrieve the browsing context tree with the current context set as the root by default.BrowsingContextAddInterceptOptions
andBrowsingContextAddPreloadScriptOptions
) to ensure context is set correctly.BrowsingContextGetTreeOptions
,BrowsingContextAddInterceptOptions
,BrowsingContextAddPreloadScriptOptions
) with internal properties to encapsulate context-specific configurations.Changes walkthrough 📝
BrowsingContext.cs
Add `GetTreeAsync` method to BrowsingContext class
dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs
GetTreeAsync
to retrieve the browsing context tree.BrowsingContextNetworkModule.cs
Update intercept methods to use specific options class
dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs
BrowsingContextAddInterceptOptions
.BrowsingContextScriptModule.cs
Update preload script method to use specific options class
dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs
AddPreloadScriptAsync
method to useBrowsingContextAddPreloadScriptOptions
.GetTreeCommand.cs
Introduce BrowsingContextGetTreeOptions for tree command
dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs
BrowsingContextGetTreeOptions
class inheriting fromGetTreeOptions
.Root
property to be internal.AddInterceptCommand.cs
Introduce BrowsingContextAddInterceptOptions for intercept command
dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs
BrowsingContextAddInterceptOptions
class inheriting fromAddInterceptOptions
.Contexts
property to be internal.AddPreloadScriptCommand.cs
Introduce BrowsingContextAddPreloadScriptOptions for preload script
command
dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs
BrowsingContextAddPreloadScriptOptions
class inheriting fromAddPreloadScriptOptions
.Contexts
property to be internal.