-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cdp] Add the ability to listen for page mutations
Note, this is a pretty rubbish implementation, and needs to be made more robust, but it suffices to show that the idea works.
- Loading branch information
Showing
14 changed files
with
332 additions
and
0 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
java/client/src/org/openqa/selenium/devtools/events/DomMutationEvent.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.openqa.selenium.devtools.events; | ||
|
||
import org.openqa.selenium.WebElement; | ||
|
||
public class DomMutationEvent { | ||
|
||
private final WebElement element; | ||
private final String attributeName; | ||
private final String currentValue; | ||
private final String oldValue; | ||
|
||
public DomMutationEvent(WebElement element, String attributeName, String currentValue, String oldValue) { | ||
this.element = element; | ||
this.attributeName = attributeName; | ||
this.currentValue = currentValue; | ||
this.oldValue = oldValue; | ||
} | ||
|
||
public WebElement getElement() { | ||
return element; | ||
} | ||
|
||
public String getAttributeName() { | ||
return attributeName; | ||
} | ||
|
||
public String getCurrentValue() { | ||
return currentValue; | ||
} | ||
|
||
public String getOldValue() { | ||
return oldValue; | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
java/client/src/org/openqa/selenium/devtools/idealized/page/Page.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.openqa.selenium.devtools.idealized.page; | ||
|
||
import org.openqa.selenium.devtools.Command; | ||
import org.openqa.selenium.devtools.idealized.page.model.ScriptIdentifier; | ||
|
||
public interface Page { | ||
|
||
Command<Void> enable(); | ||
|
||
Command<ScriptIdentifier> addScriptToEvaluateOnNewDocument(String source); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
java/client/src/org/openqa/selenium/devtools/idealized/page/model/ScriptIdentifier.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.openqa.selenium.devtools.idealized.page.model; | ||
|
||
import org.openqa.selenium.internal.Require; | ||
|
||
public class ScriptIdentifier { | ||
|
||
private final Object actualIdentifier; | ||
|
||
public ScriptIdentifier(Object actualIdentifier) { | ||
this.actualIdentifier = Require.nonNull("Actual identifier", actualIdentifier); | ||
} | ||
|
||
public Object getActualIdentifier() { | ||
return actualIdentifier; | ||
} | ||
|
||
} |
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
30 changes: 30 additions & 0 deletions
30
java/client/src/org/openqa/selenium/devtools/idealized/runtime/model/BindingCalled.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.openqa.selenium.devtools.idealized.runtime.model; | ||
|
||
import org.openqa.selenium.internal.Require; | ||
|
||
public class BindingCalled { | ||
|
||
private final String name; | ||
private final String payload; | ||
|
||
public BindingCalled(String name, String payload) { | ||
this.name = Require.nonNull("Name", name); | ||
this.payload = Require.nonNull("Payload", payload); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getPayload() { | ||
return payload; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BindingCalled{" + | ||
"name='" + name + '\'' + | ||
", payload='" + payload + '\'' + | ||
'}'; | ||
} | ||
} |
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
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
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
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
36 changes: 36 additions & 0 deletions
36
java/client/src/org/openqa/selenium/devtools/v85/V85Page.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.openqa.selenium.devtools.v85; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.openqa.selenium.devtools.Command; | ||
import org.openqa.selenium.devtools.ConverterFunctions; | ||
import org.openqa.selenium.devtools.idealized.page.Page; | ||
import org.openqa.selenium.devtools.v85.page.model.ScriptIdentifier; | ||
import org.openqa.selenium.internal.Require; | ||
import org.openqa.selenium.json.JsonInput; | ||
|
||
import java.util.function.Function; | ||
|
||
public class V85Page implements Page { | ||
|
||
@Override | ||
public Command<Void> enable() { | ||
return org.openqa.selenium.devtools.v85.page.Page.enable(); | ||
} | ||
|
||
@Override | ||
public Command<org.openqa.selenium.devtools.idealized.page.model.ScriptIdentifier> addScriptToEvaluateOnNewDocument(String source) { | ||
Require.nonNull("Source", source); | ||
ImmutableMap.Builder<String, Object> params = ImmutableMap.builder(); | ||
params.put("source", source); | ||
|
||
Function<JsonInput, ScriptIdentifier> mapper = ConverterFunctions.map("identifier", ScriptIdentifier.class); | ||
|
||
return new Command<>( | ||
"Page.addScriptToEvaluateOnNewDocument", | ||
ImmutableMap.of("source", source), | ||
input -> { | ||
ScriptIdentifier actualId = mapper.apply(input); | ||
return new org.openqa.selenium.devtools.idealized.page.model.ScriptIdentifier(actualId); | ||
}); | ||
} | ||
} |
Oops, something went wrong.