diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Protocol.java b/playwright/src/main/java/com/microsoft/playwright/impl/Protocol.java index 3c4170ec0..10589bc9a 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Protocol.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Protocol.java @@ -47,6 +47,10 @@ public static class O { Number h; Integer id; Integer ref; + // JS representation of Map: [[key1, value1], [key2, value2], ...]. + SerializedValue m; + // JS representation of Set: [item1, item2, ...]. + SerializedValue se; } class SerializedArgument{ diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java index b5d9f2568..8b2588bc4 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Serialization.java @@ -280,6 +280,16 @@ private static T deserialize(SerializedValue value, Map idT } return (T) map; } + if (value.m != null) { + Map map = new LinkedHashMap<>(); + idToValue.put(value.id, map); + return (T) map; + } + if (value.se != null) { + Map map = new LinkedHashMap<>(); + idToValue.put(value.id, map); + return (T) map; + } throw new PlaywrightException("Unexpected result: " + gson().toJson(value)); } diff --git a/playwright/src/test/java/com/microsoft/playwright/TestPageEvaluate.java b/playwright/src/test/java/com/microsoft/playwright/TestPageEvaluate.java index 10da53c71..f426a0250 100644 --- a/playwright/src/test/java/com/microsoft/playwright/TestPageEvaluate.java +++ b/playwright/src/test/java/com/microsoft/playwright/TestPageEvaluate.java @@ -645,4 +645,14 @@ void shouldAcceptParameter() { assertTrue(object instanceof Date); assertEquals(Date.from(instant), object); } + + @Test + void shouldTransferMaps() { + assertEquals(mapOf(), page.evaluate("() => new Map([[1, { test: 42n }]])")); + } + + @Test + void shouldTransferSets() { + assertEquals(mapOf(), page.evaluate("() => new Set([1, { test: 42n }])")); + } }