Skip to content

Commit 8d5c10f

Browse files
committed
[java][cdp] add support for Chrome 108 and remove support for Chrome 105
1 parent 69fac46 commit 8d5c10f

File tree

10 files changed

+808
-2
lines changed

10 files changed

+808
-2
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ task '//java/test/org/openqa/selenium/environment/webserver:webserver:uber' => [
9898
JAVA_RELEASE_TARGETS = %w[
9999
//java/src/org/openqa/selenium/chrome:chrome.publish
100100
//java/src/org/openqa/selenium/chromium:chromium.publish
101-
//java/src/org/openqa/selenium/devtools/v105:v105.publish
102101
//java/src/org/openqa/selenium/devtools/v106:v106.publish
103102
//java/src/org/openqa/selenium/devtools/v107:v107.publish
103+
//java/src/org/openqa/selenium/devtools/v108:v108.publish
104104
//java/src/org/openqa/selenium/devtools/v85:v85.publish
105105
//java/src/org/openqa/selenium/edge:edge.publish
106106
//java/src/org/openqa/selenium/firefox:firefox.publish
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
load("@rules_jvm_external//:defs.bzl", "artifact")
2+
load("//common:defs.bzl", "copy_file")
3+
load("//java:defs.bzl", "java_export", "java_library")
4+
load("//java:version.bzl", "SE_VERSION")
5+
6+
cdp_version = "v108"
7+
8+
java_export(
9+
name = cdp_version,
10+
srcs = glob(["*.java"]),
11+
maven_coordinates = "org.seleniumhq.selenium:selenium-devtools-%s:%s" % (cdp_version, SE_VERSION),
12+
opens_to = [
13+
"org.openqa.selenium.json",
14+
],
15+
pom_template = "//java/src/org/openqa/selenium:template-pom",
16+
visibility = [
17+
"//visibility:public",
18+
],
19+
exports = [
20+
":cdp",
21+
],
22+
deps = [
23+
":cdp",
24+
"//java:auto-service",
25+
"//java/src/org/openqa/selenium:core",
26+
"//java/src/org/openqa/selenium/json",
27+
"//java/src/org/openqa/selenium/remote",
28+
artifact("com.google.guava:guava"),
29+
],
30+
)
31+
32+
java_library(
33+
name = "cdp",
34+
srcs = [
35+
":create-cdp-srcs",
36+
],
37+
tags = [
38+
"no-lint",
39+
],
40+
deps = [
41+
"//java/src/org/openqa/selenium:core",
42+
"//java/src/org/openqa/selenium/json",
43+
"//java/src/org/openqa/selenium/remote",
44+
artifact("com.google.guava:guava"),
45+
],
46+
)
47+
48+
genrule(
49+
name = "create-cdp-srcs",
50+
srcs = [
51+
":browser_protocol",
52+
":js_protocol",
53+
],
54+
outs = ["cdp.srcjar"],
55+
cmd = "$(location //java/src/org/openqa/selenium/devtools:cdp-client-generator) $(location :browser_protocol) $(location :js_protocol) %s $@" % cdp_version,
56+
tools = [
57+
"//java/src/org/openqa/selenium/devtools:cdp-client-generator",
58+
],
59+
)
60+
61+
copy_file(
62+
name = "browser_protocol",
63+
src = "//common/devtools/chromium/%s:browser_protocol" % cdp_version,
64+
out = "browser_protocol.json",
65+
)
66+
67+
copy_file(
68+
name = "js_protocol",
69+
src = "//common/devtools/chromium/%s:js_protocol" % cdp_version,
70+
out = "js_protocol.json",
71+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.devtools.v108;
19+
20+
import com.google.auto.service.AutoService;
21+
import org.openqa.selenium.devtools.CdpInfo;
22+
23+
@AutoService(CdpInfo.class)
24+
public class V108CdpInfo extends CdpInfo {
25+
26+
public V108CdpInfo() {
27+
super(108, V108Domains::new);
28+
}
29+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.devtools.v108;
19+
20+
import org.openqa.selenium.devtools.DevTools;
21+
import org.openqa.selenium.devtools.idealized.Domains;
22+
import org.openqa.selenium.devtools.idealized.Events;
23+
import org.openqa.selenium.devtools.idealized.Javascript;
24+
import org.openqa.selenium.devtools.idealized.Network;
25+
import org.openqa.selenium.devtools.idealized.log.Log;
26+
import org.openqa.selenium.devtools.idealized.target.Target;
27+
import org.openqa.selenium.internal.Require;
28+
29+
public class V108Domains implements Domains {
30+
31+
private final V108Javascript js;
32+
private final V108Events events;
33+
private final V108Log log;
34+
private final V108Network network;
35+
private final V108Target target;
36+
37+
public V108Domains(DevTools devtools) {
38+
Require.nonNull("DevTools", devtools);
39+
events = new V108Events(devtools);
40+
js = new V108Javascript(devtools);
41+
log = new V108Log();
42+
network = new V108Network(devtools);
43+
target = new V108Target();
44+
}
45+
46+
@Override
47+
public Events<?, ?> events() {
48+
return events;
49+
}
50+
51+
@Override
52+
public Javascript<?, ?> javascript() {
53+
return js;
54+
}
55+
56+
@Override
57+
public Network<?, ?> network() {
58+
return network;
59+
}
60+
61+
@Override
62+
public Target target() {
63+
return target;
64+
}
65+
66+
@Override
67+
public Log log() {
68+
return log;
69+
}
70+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.devtools.v108;
19+
20+
import com.google.common.collect.ImmutableList;
21+
22+
import org.openqa.selenium.JavascriptException;
23+
import org.openqa.selenium.devtools.Command;
24+
import org.openqa.selenium.devtools.DevTools;
25+
import org.openqa.selenium.devtools.Event;
26+
import org.openqa.selenium.devtools.events.ConsoleEvent;
27+
import org.openqa.selenium.devtools.idealized.Events;
28+
import org.openqa.selenium.devtools.idealized.runtime.model.RemoteObject;
29+
import org.openqa.selenium.devtools.v108.runtime.Runtime;
30+
import org.openqa.selenium.devtools.v108.runtime.model.ConsoleAPICalled;
31+
import org.openqa.selenium.devtools.v108.runtime.model.ExceptionDetails;
32+
import org.openqa.selenium.devtools.v108.runtime.model.ExceptionThrown;
33+
import org.openqa.selenium.devtools.v108.runtime.model.StackTrace;
34+
35+
import java.time.Instant;
36+
import java.util.List;
37+
import java.util.Optional;
38+
39+
public class V108Events extends Events<ConsoleAPICalled, ExceptionThrown> {
40+
41+
public V108Events(DevTools devtools) {
42+
super(devtools);
43+
}
44+
45+
@Override
46+
protected Command<Void> enableRuntime() {
47+
return Runtime.enable();
48+
}
49+
50+
@Override
51+
protected Command<Void> disableRuntime() {
52+
return Runtime.disable();
53+
}
54+
55+
@Override
56+
protected Event<ConsoleAPICalled> consoleEvent() {
57+
return Runtime.consoleAPICalled();
58+
}
59+
60+
@Override
61+
protected Event<ExceptionThrown> exceptionThrownEvent() {
62+
return Runtime.exceptionThrown();
63+
}
64+
65+
@Override
66+
protected ConsoleEvent toConsoleEvent(ConsoleAPICalled event) {
67+
long ts = event.getTimestamp().toJson().longValue();
68+
69+
List<Object> modifiedArgs = event.getArgs().stream()
70+
.map(obj -> new RemoteObject(
71+
obj.getType().toString(),
72+
obj.getValue().orElse(null)))
73+
.collect(ImmutableList.toImmutableList());
74+
75+
return new ConsoleEvent(
76+
event.getType().toString(),
77+
Instant.ofEpochMilli(ts),
78+
modifiedArgs);
79+
}
80+
81+
@Override
82+
protected JavascriptException toJsException(ExceptionThrown event) {
83+
ExceptionDetails details = event.getExceptionDetails();
84+
Optional<StackTrace> maybeTrace = details.getStackTrace();
85+
Optional<org.openqa.selenium.devtools.v108.runtime.model.RemoteObject>
86+
maybeException = details.getException();
87+
88+
String message = maybeException
89+
.flatMap(obj -> obj.getDescription().map(String::toString))
90+
.orElseGet(details::getText);
91+
92+
JavascriptException exception = new JavascriptException(message);
93+
94+
if (!maybeTrace.isPresent()) {
95+
StackTraceElement element = new StackTraceElement(
96+
"unknown",
97+
"unknown",
98+
details.getUrl().orElse("unknown"),
99+
details.getLineNumber());
100+
exception.setStackTrace(new StackTraceElement[]{element});
101+
return exception;
102+
}
103+
104+
StackTrace trace = maybeTrace.get();
105+
106+
exception.setStackTrace(trace.getCallFrames().stream()
107+
.map(frame -> new StackTraceElement(
108+
"",
109+
frame.getFunctionName(),
110+
frame.getUrl(),
111+
frame.getLineNumber()))
112+
.toArray(StackTraceElement[]::new));
113+
114+
return exception;
115+
}
116+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.devtools.v108;
19+
20+
import org.openqa.selenium.devtools.Command;
21+
import org.openqa.selenium.devtools.DevTools;
22+
import org.openqa.selenium.devtools.Event;
23+
import org.openqa.selenium.devtools.idealized.Javascript;
24+
import org.openqa.selenium.devtools.v108.page.Page;
25+
import org.openqa.selenium.devtools.v108.page.model.ScriptIdentifier;
26+
import org.openqa.selenium.devtools.v108.runtime.Runtime;
27+
import org.openqa.selenium.devtools.v108.runtime.model.BindingCalled;
28+
29+
import java.util.Optional;
30+
31+
public class V108Javascript extends Javascript<ScriptIdentifier, BindingCalled> {
32+
33+
public V108Javascript(DevTools devtools) {
34+
super(devtools);
35+
}
36+
37+
@Override
38+
protected Command<Void> enableRuntime() {
39+
return Runtime.enable();
40+
}
41+
42+
@Override
43+
protected Command<Void> disableRuntime() {
44+
return Runtime.disable();
45+
}
46+
47+
@Override
48+
protected Command<Void> doAddJsBinding(String scriptName) {
49+
return Runtime.addBinding(scriptName, Optional.empty(), Optional.empty());
50+
}
51+
52+
@Override
53+
protected Command<Void> doRemoveJsBinding(String scriptName) {
54+
return Runtime.removeBinding(scriptName);
55+
}
56+
57+
@Override
58+
protected Command<Void> enablePage() {
59+
return Page.enable();
60+
}
61+
62+
@Override
63+
protected Command<Void> disablePage() {
64+
return Page.disable();
65+
}
66+
67+
@Override
68+
protected Command<ScriptIdentifier> addScriptToEvaluateOnNewDocument(String script) {
69+
return Page.addScriptToEvaluateOnNewDocument(script, Optional.empty(), Optional.empty());
70+
}
71+
72+
@Override
73+
protected Command<Void> removeScriptToEvaluateOnNewDocument(ScriptIdentifier id) {
74+
return Page.removeScriptToEvaluateOnNewDocument(id);
75+
}
76+
77+
@Override
78+
protected Event<BindingCalled> bindingCalledEvent() {
79+
return Runtime.bindingCalled();
80+
}
81+
82+
@Override
83+
protected String extractPayload(BindingCalled event) {
84+
return event.getPayload();
85+
}
86+
}

0 commit comments

Comments
 (0)