Skip to content

Commit e0082a8

Browse files
committed
[cdp] Add v85 support for Firefox
1 parent 6c405ea commit e0082a8

File tree

10 files changed

+699
-0
lines changed

10 files changed

+699
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
java_export(
7+
name = "v85",
8+
srcs = glob(["*.java"]),
9+
maven_coordinates = "org.seleniumhq.selenium:selenium-devtools-v85:%s" % SE_VERSION,
10+
opens_to = [
11+
"org.openqa.selenium.json",
12+
],
13+
pom_template = "//java/client/src/org/openqa/selenium:template-pom",
14+
visibility = [
15+
"//visibility:public",
16+
],
17+
exports = [
18+
":cdp",
19+
],
20+
deps = [
21+
":cdp",
22+
"//java:auto-service",
23+
"//java/client/src/org/openqa/selenium:core",
24+
"//java/client/src/org/openqa/selenium/devtools",
25+
"//java/client/src/org/openqa/selenium/json",
26+
"//java/client/src/org/openqa/selenium/remote/http",
27+
artifact("com.google.guava:guava"),
28+
],
29+
)
30+
31+
java_library(
32+
name = "cdp",
33+
srcs = [
34+
":create-cdp-srcs",
35+
],
36+
tags = [
37+
"no-lint",
38+
],
39+
deps = [
40+
"//java/client/src/org/openqa/selenium:core",
41+
"//java/client/src/org/openqa/selenium/devtools",
42+
"//java/client/src/org/openqa/selenium/json",
43+
artifact("com.google.guava:guava"),
44+
],
45+
)
46+
47+
genrule(
48+
name = "create-cdp-srcs",
49+
srcs = [
50+
":browser_protocol",
51+
":js_protocol",
52+
],
53+
outs = ["cdp.srcjar"],
54+
cmd = "$(location //java/client/src/org/openqa/selenium/devtools:cdp-client-generator) $(location :browser_protocol) $(location :js_protocol) v85 $@",
55+
tools = [
56+
"//java/client/src/org/openqa/selenium/devtools:cdp-client-generator",
57+
],
58+
)
59+
60+
copy_file(
61+
name = "browser_protocol",
62+
src = "//common/devtools/chromium/v85:browser_protocol",
63+
out = "browser_protocol.json",
64+
)
65+
66+
copy_file(
67+
name = "js_protocol",
68+
src = "//common/devtools/chromium/v85:js_protocol",
69+
out = "js_protocol.json",
70+
)
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.v85;
19+
20+
import com.google.auto.service.AutoService;
21+
import org.openqa.selenium.devtools.CdpInfo;
22+
23+
@AutoService(CdpInfo.class)
24+
public class V85CdpInfo extends CdpInfo {
25+
26+
public V85CdpInfo() {
27+
super(85, V85Domains::new);
28+
}
29+
}
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.v85;
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 V85Domains implements Domains {
30+
31+
private final V85Javascript js;
32+
private final V85Events events;
33+
private final V85Log log;
34+
private final V85Network network;
35+
private final V85Target target;
36+
37+
public V85Domains(DevTools devtools) {
38+
Require.nonNull("DevTools", devtools);
39+
events = new V85Events(devtools);
40+
js = new V85Javascript(devtools);
41+
log = new V85Log();
42+
network = new V85Network(devtools);
43+
target = new V85Target();
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+
}
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.v85;
19+
20+
import com.google.common.collect.ImmutableList;
21+
import org.openqa.selenium.JavascriptException;
22+
import org.openqa.selenium.devtools.Command;
23+
import org.openqa.selenium.devtools.DevTools;
24+
import org.openqa.selenium.devtools.Event;
25+
import org.openqa.selenium.devtools.events.ConsoleEvent;
26+
import org.openqa.selenium.devtools.idealized.Events;
27+
import org.openqa.selenium.devtools.idealized.runtime.model.RemoteObject;
28+
import org.openqa.selenium.devtools.v85.runtime.Runtime;
29+
import org.openqa.selenium.devtools.v85.runtime.model.ConsoleAPICalled;
30+
import org.openqa.selenium.devtools.v85.runtime.model.ExceptionDetails;
31+
import org.openqa.selenium.devtools.v85.runtime.model.ExceptionThrown;
32+
import org.openqa.selenium.devtools.v85.runtime.model.StackTrace;
33+
34+
import java.math.BigDecimal;
35+
import java.time.Instant;
36+
import java.util.List;
37+
import java.util.Optional;
38+
39+
public class V85Events extends Events<ConsoleAPICalled, ExceptionThrown> {
40+
41+
public V85Events(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 = new BigDecimal(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.v85.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+
}
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.v85;
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.v85.page.Page;
25+
import org.openqa.selenium.devtools.v85.page.model.ScriptIdentifier;
26+
import org.openqa.selenium.devtools.v85.runtime.Runtime;
27+
import org.openqa.selenium.devtools.v85.runtime.model.BindingCalled;
28+
29+
import java.util.Optional;
30+
31+
public class V85Javascript extends Javascript<ScriptIdentifier, BindingCalled> {
32+
33+
public V85Javascript(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());
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());
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)