diff --git a/java/src/org/openqa/selenium/safari/AddHasPermissions.java b/java/src/org/openqa/selenium/safari/AddHasPermissions.java index 7757579d7a113..96e49bdb54084 100644 --- a/java/src/org/openqa/selenium/safari/AddHasPermissions.java +++ b/java/src/org/openqa/selenium/safari/AddHasPermissions.java @@ -18,6 +18,7 @@ package org.openqa.selenium.safari; import com.google.auto.service.AutoService; +import java.util.HashMap; import java.util.Map; import java.util.function.Predicate; import org.openqa.selenium.Capabilities; @@ -66,9 +67,21 @@ public void setPermissions(String permission, boolean value) { @Override public Map getPermissions() { - Map results = - (Map) executeMethod.execute(GET_PERMISSIONS, null); - return (Map) results.get("permissions"); + Object resultObject = executeMethod.execute(GET_PERMISSIONS, null); + + if (resultObject instanceof Map) { + Map resultMap = (Map) resultObject; + Map permissionMap = new HashMap<>(); + for (Map.Entry entry : resultMap.entrySet()) { + if (entry.getKey() instanceof String && entry.getValue() instanceof Boolean) { + permissionMap.put((String) entry.getKey(), (Boolean) entry.getValue()); + } + } + return permissionMap; + } else { + throw new IllegalStateException( + "Unexpected result type: " + resultObject.getClass().getName()); + } } }; }