MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / RemoteScript

Class RemoteScript

java/src/org/openqa/selenium/remote/RemoteScript.java:47–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45import org.openqa.selenium.json.Json;
46
47@Beta
48class RemoteScript implements Script {
49
50 private static final Json JSON = new Json();
51 private final BiDi biDi;
52 private final LogInspector logInspector;
53 private final org.openqa.selenium.bidi.module.Script script;
54
55 private final WebDriver driver;
56
57 public RemoteScript(WebDriver driver) {
58 this.driver = driver;
59 this.biDi = ((HasBiDi) driver).getBiDi();
60 this.logInspector = new LogInspector(driver);
61 this.script = new org.openqa.selenium.bidi.module.Script(driver);
62 }
63
64 @Override
65 public long addConsoleMessageHandler(Consumer<ConsoleLogEntry> consumer) {
66 return this.logInspector.onConsoleEntry(consumer);
67 }
68
69 @Override
70 public void removeConsoleMessageHandler(long id) {
71 this.biDi.removeListener(id);
72 }
73
74 @Override
75 public long addJavaScriptErrorHandler(Consumer<JavascriptLogEntry> consumer) {
76 return this.logInspector.onJavaScriptException(consumer);
77 }
78
79 @Override
80 public void removeJavaScriptErrorHandler(long id) {
81 this.biDi.removeListener(id);
82 }
83
84 @Override
85 public long addDomMutationHandler(Consumer<DomMutation> consumer) {
86 String scriptValue =
87 Read.resourceAsString(getClass(), "/org/openqa/selenium/remote/bidi-mutation-listener.js");
88
89 this.script.addPreloadScript(scriptValue, List.of(new ChannelValue("channel_name")));
90
91 return this.script.onMessage(
92 message -> {
93 String value = message.getData().getValue().get().toString();
94
95 Map<String, Object> values = JSON.toType(value, MAP_TYPE);
96 String id = (String) values.get("target");
97
98 List<WebElement> elements;
99
100 synchronized (this) {
101 elements =
102 this.driver.findElements(
103 By.cssSelector(String.format("*[data-__webdriver_id='%s']", id)));
104 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected