-
-
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.
[java][cdp] add support for Chrome 108 and remove support for Chrome 105
- Loading branch information
1 parent
69fac46
commit 8d5c10f
Showing
10 changed files
with
808 additions
and
2 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
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,71 @@ | ||
load("@rules_jvm_external//:defs.bzl", "artifact") | ||
load("//common:defs.bzl", "copy_file") | ||
load("//java:defs.bzl", "java_export", "java_library") | ||
load("//java:version.bzl", "SE_VERSION") | ||
|
||
cdp_version = "v108" | ||
|
||
java_export( | ||
name = cdp_version, | ||
srcs = glob(["*.java"]), | ||
maven_coordinates = "org.seleniumhq.selenium:selenium-devtools-%s:%s" % (cdp_version, SE_VERSION), | ||
opens_to = [ | ||
"org.openqa.selenium.json", | ||
], | ||
pom_template = "//java/src/org/openqa/selenium:template-pom", | ||
visibility = [ | ||
"//visibility:public", | ||
], | ||
exports = [ | ||
":cdp", | ||
], | ||
deps = [ | ||
":cdp", | ||
"//java:auto-service", | ||
"//java/src/org/openqa/selenium:core", | ||
"//java/src/org/openqa/selenium/json", | ||
"//java/src/org/openqa/selenium/remote", | ||
artifact("com.google.guava:guava"), | ||
], | ||
) | ||
|
||
java_library( | ||
name = "cdp", | ||
srcs = [ | ||
":create-cdp-srcs", | ||
], | ||
tags = [ | ||
"no-lint", | ||
], | ||
deps = [ | ||
"//java/src/org/openqa/selenium:core", | ||
"//java/src/org/openqa/selenium/json", | ||
"//java/src/org/openqa/selenium/remote", | ||
artifact("com.google.guava:guava"), | ||
], | ||
) | ||
|
||
genrule( | ||
name = "create-cdp-srcs", | ||
srcs = [ | ||
":browser_protocol", | ||
":js_protocol", | ||
], | ||
outs = ["cdp.srcjar"], | ||
cmd = "$(location //java/src/org/openqa/selenium/devtools:cdp-client-generator) $(location :browser_protocol) $(location :js_protocol) %s $@" % cdp_version, | ||
tools = [ | ||
"//java/src/org/openqa/selenium/devtools:cdp-client-generator", | ||
], | ||
) | ||
|
||
copy_file( | ||
name = "browser_protocol", | ||
src = "//common/devtools/chromium/%s:browser_protocol" % cdp_version, | ||
out = "browser_protocol.json", | ||
) | ||
|
||
copy_file( | ||
name = "js_protocol", | ||
src = "//common/devtools/chromium/%s:js_protocol" % cdp_version, | ||
out = "js_protocol.json", | ||
) |
29 changes: 29 additions & 0 deletions
29
java/src/org/openqa/selenium/devtools/v108/V108CdpInfo.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,29 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.devtools.v108; | ||
|
||
import com.google.auto.service.AutoService; | ||
import org.openqa.selenium.devtools.CdpInfo; | ||
|
||
@AutoService(CdpInfo.class) | ||
public class V108CdpInfo extends CdpInfo { | ||
|
||
public V108CdpInfo() { | ||
super(108, V108Domains::new); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
java/src/org/openqa/selenium/devtools/v108/V108Domains.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,70 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.devtools.v108; | ||
|
||
import org.openqa.selenium.devtools.DevTools; | ||
import org.openqa.selenium.devtools.idealized.Domains; | ||
import org.openqa.selenium.devtools.idealized.Events; | ||
import org.openqa.selenium.devtools.idealized.Javascript; | ||
import org.openqa.selenium.devtools.idealized.Network; | ||
import org.openqa.selenium.devtools.idealized.log.Log; | ||
import org.openqa.selenium.devtools.idealized.target.Target; | ||
import org.openqa.selenium.internal.Require; | ||
|
||
public class V108Domains implements Domains { | ||
|
||
private final V108Javascript js; | ||
private final V108Events events; | ||
private final V108Log log; | ||
private final V108Network network; | ||
private final V108Target target; | ||
|
||
public V108Domains(DevTools devtools) { | ||
Require.nonNull("DevTools", devtools); | ||
events = new V108Events(devtools); | ||
js = new V108Javascript(devtools); | ||
log = new V108Log(); | ||
network = new V108Network(devtools); | ||
target = new V108Target(); | ||
} | ||
|
||
@Override | ||
public Events<?, ?> events() { | ||
return events; | ||
} | ||
|
||
@Override | ||
public Javascript<?, ?> javascript() { | ||
return js; | ||
} | ||
|
||
@Override | ||
public Network<?, ?> network() { | ||
return network; | ||
} | ||
|
||
@Override | ||
public Target target() { | ||
return target; | ||
} | ||
|
||
@Override | ||
public Log log() { | ||
return log; | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
java/src/org/openqa/selenium/devtools/v108/V108Events.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,116 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.devtools.v108; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import org.openqa.selenium.JavascriptException; | ||
import org.openqa.selenium.devtools.Command; | ||
import org.openqa.selenium.devtools.DevTools; | ||
import org.openqa.selenium.devtools.Event; | ||
import org.openqa.selenium.devtools.events.ConsoleEvent; | ||
import org.openqa.selenium.devtools.idealized.Events; | ||
import org.openqa.selenium.devtools.idealized.runtime.model.RemoteObject; | ||
import org.openqa.selenium.devtools.v108.runtime.Runtime; | ||
import org.openqa.selenium.devtools.v108.runtime.model.ConsoleAPICalled; | ||
import org.openqa.selenium.devtools.v108.runtime.model.ExceptionDetails; | ||
import org.openqa.selenium.devtools.v108.runtime.model.ExceptionThrown; | ||
import org.openqa.selenium.devtools.v108.runtime.model.StackTrace; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class V108Events extends Events<ConsoleAPICalled, ExceptionThrown> { | ||
|
||
public V108Events(DevTools devtools) { | ||
super(devtools); | ||
} | ||
|
||
@Override | ||
protected Command<Void> enableRuntime() { | ||
return Runtime.enable(); | ||
} | ||
|
||
@Override | ||
protected Command<Void> disableRuntime() { | ||
return Runtime.disable(); | ||
} | ||
|
||
@Override | ||
protected Event<ConsoleAPICalled> consoleEvent() { | ||
return Runtime.consoleAPICalled(); | ||
} | ||
|
||
@Override | ||
protected Event<ExceptionThrown> exceptionThrownEvent() { | ||
return Runtime.exceptionThrown(); | ||
} | ||
|
||
@Override | ||
protected ConsoleEvent toConsoleEvent(ConsoleAPICalled event) { | ||
long ts = event.getTimestamp().toJson().longValue(); | ||
|
||
List<Object> modifiedArgs = event.getArgs().stream() | ||
.map(obj -> new RemoteObject( | ||
obj.getType().toString(), | ||
obj.getValue().orElse(null))) | ||
.collect(ImmutableList.toImmutableList()); | ||
|
||
return new ConsoleEvent( | ||
event.getType().toString(), | ||
Instant.ofEpochMilli(ts), | ||
modifiedArgs); | ||
} | ||
|
||
@Override | ||
protected JavascriptException toJsException(ExceptionThrown event) { | ||
ExceptionDetails details = event.getExceptionDetails(); | ||
Optional<StackTrace> maybeTrace = details.getStackTrace(); | ||
Optional<org.openqa.selenium.devtools.v108.runtime.model.RemoteObject> | ||
maybeException = details.getException(); | ||
|
||
String message = maybeException | ||
.flatMap(obj -> obj.getDescription().map(String::toString)) | ||
.orElseGet(details::getText); | ||
|
||
JavascriptException exception = new JavascriptException(message); | ||
|
||
if (!maybeTrace.isPresent()) { | ||
StackTraceElement element = new StackTraceElement( | ||
"unknown", | ||
"unknown", | ||
details.getUrl().orElse("unknown"), | ||
details.getLineNumber()); | ||
exception.setStackTrace(new StackTraceElement[]{element}); | ||
return exception; | ||
} | ||
|
||
StackTrace trace = maybeTrace.get(); | ||
|
||
exception.setStackTrace(trace.getCallFrames().stream() | ||
.map(frame -> new StackTraceElement( | ||
"", | ||
frame.getFunctionName(), | ||
frame.getUrl(), | ||
frame.getLineNumber())) | ||
.toArray(StackTraceElement[]::new)); | ||
|
||
return exception; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
java/src/org/openqa/selenium/devtools/v108/V108Javascript.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,86 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.devtools.v108; | ||
|
||
import org.openqa.selenium.devtools.Command; | ||
import org.openqa.selenium.devtools.DevTools; | ||
import org.openqa.selenium.devtools.Event; | ||
import org.openqa.selenium.devtools.idealized.Javascript; | ||
import org.openqa.selenium.devtools.v108.page.Page; | ||
import org.openqa.selenium.devtools.v108.page.model.ScriptIdentifier; | ||
import org.openqa.selenium.devtools.v108.runtime.Runtime; | ||
import org.openqa.selenium.devtools.v108.runtime.model.BindingCalled; | ||
|
||
import java.util.Optional; | ||
|
||
public class V108Javascript extends Javascript<ScriptIdentifier, BindingCalled> { | ||
|
||
public V108Javascript(DevTools devtools) { | ||
super(devtools); | ||
} | ||
|
||
@Override | ||
protected Command<Void> enableRuntime() { | ||
return Runtime.enable(); | ||
} | ||
|
||
@Override | ||
protected Command<Void> disableRuntime() { | ||
return Runtime.disable(); | ||
} | ||
|
||
@Override | ||
protected Command<Void> doAddJsBinding(String scriptName) { | ||
return Runtime.addBinding(scriptName, Optional.empty(), Optional.empty()); | ||
} | ||
|
||
@Override | ||
protected Command<Void> doRemoveJsBinding(String scriptName) { | ||
return Runtime.removeBinding(scriptName); | ||
} | ||
|
||
@Override | ||
protected Command<Void> enablePage() { | ||
return Page.enable(); | ||
} | ||
|
||
@Override | ||
protected Command<Void> disablePage() { | ||
return Page.disable(); | ||
} | ||
|
||
@Override | ||
protected Command<ScriptIdentifier> addScriptToEvaluateOnNewDocument(String script) { | ||
return Page.addScriptToEvaluateOnNewDocument(script, Optional.empty(), Optional.empty()); | ||
} | ||
|
||
@Override | ||
protected Command<Void> removeScriptToEvaluateOnNewDocument(ScriptIdentifier id) { | ||
return Page.removeScriptToEvaluateOnNewDocument(id); | ||
} | ||
|
||
@Override | ||
protected Event<BindingCalled> bindingCalledEvent() { | ||
return Runtime.bindingCalled(); | ||
} | ||
|
||
@Override | ||
protected String extractPayload(BindingCalled event) { | ||
return event.getPayload(); | ||
} | ||
} |
Oops, something went wrong.