Skip to content

Commit

Permalink
[java][cdp] add support for Chrome 108 and remove support for Chrome 105
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Nov 30, 2022
1 parent 69fac46 commit 8d5c10f
Show file tree
Hide file tree
Showing 10 changed files with 808 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ task '//java/test/org/openqa/selenium/environment/webserver:webserver:uber' => [
JAVA_RELEASE_TARGETS = %w[
//java/src/org/openqa/selenium/chrome:chrome.publish
//java/src/org/openqa/selenium/chromium:chromium.publish
//java/src/org/openqa/selenium/devtools/v105:v105.publish
//java/src/org/openqa/selenium/devtools/v106:v106.publish
//java/src/org/openqa/selenium/devtools/v107:v107.publish
//java/src/org/openqa/selenium/devtools/v108:v108.publish
//java/src/org/openqa/selenium/devtools/v85:v85.publish
//java/src/org/openqa/selenium/edge:edge.publish
//java/src/org/openqa/selenium/firefox:firefox.publish
Expand Down
71 changes: 71 additions & 0 deletions java/src/org/openqa/selenium/devtools/v108/BUILD.bazel
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 java/src/org/openqa/selenium/devtools/v108/V108CdpInfo.java
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 java/src/org/openqa/selenium/devtools/v108/V108Domains.java
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 java/src/org/openqa/selenium/devtools/v108/V108Events.java
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 java/src/org/openqa/selenium/devtools/v108/V108Javascript.java
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();
}
}
Loading

0 comments on commit 8d5c10f

Please sign in to comment.