Skip to content

Commit

Permalink
[bidi][java] Avoid creating new instances of log entry event
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Jul 3, 2024
1 parent 06e7b7a commit 5e8d6a1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions java/src/org/openqa/selenium/bidi/module/LogInspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.function.Consumer;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.bidi.BiDi;
import org.openqa.selenium.bidi.Event;
import org.openqa.selenium.bidi.HasBiDi;
import org.openqa.selenium.bidi.log.BaseLogEntry;
import org.openqa.selenium.bidi.log.ConsoleLogEntry;
Expand All @@ -36,7 +37,7 @@
import org.openqa.selenium.internal.Require;

public class LogInspector implements AutoCloseable {

private final Event<LogEntry> logEntryAddedEvent;
private final Set<String> browsingContextIds;

private final BiDi bidi;
Expand All @@ -59,6 +60,7 @@ public LogInspector(Set<String> browsingContextIds, WebDriver driver) {

this.bidi = ((HasBiDi) driver).getBiDi();
this.browsingContextIds = browsingContextIds;
this.logEntryAddedEvent = Log.entryAdded();
}

public long onConsoleEntry(Consumer<ConsoleLogEntry> consumer) {
Expand Down Expand Up @@ -165,9 +167,9 @@ public void onLog(Consumer<LogEntry> consumer, FilterBy filter) {

private long addLogEntryAddedListener(Consumer<LogEntry> consumer) {
if (browsingContextIds.isEmpty()) {
return this.bidi.addListener(Log.entryAdded(), consumer);
return this.bidi.addListener(this.logEntryAddedEvent, consumer);
} else {
return this.bidi.addListener(browsingContextIds, Log.entryAdded(), consumer);
return this.bidi.addListener(browsingContextIds, this.logEntryAddedEvent, consumer);
}
}

Expand Down

0 comments on commit 5e8d6a1

Please sign in to comment.