diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/ArtifactImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/ArtifactImpl.java index ce83e2c6a..7a70b121d 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/ArtifactImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/ArtifactImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of artifact.ts. package com.microsoft.playwright.impl; import com.microsoft.playwright.impl.protocol.*; @@ -35,10 +36,36 @@ public ArtifactImpl(ChannelOwner parent, String type, String guid, JsonObject in super(parent, type, guid, initializer); } + public Path pathAfterFinished() { + if (connection.isRemote()) { + // java: the message names the Java API. + throw new PlaywrightException("Path is not available when using browserType.connect(). Use download.saveAs() to save a local copy."); + } + return FileSystems.getDefault().getPath(channel.pathAfterFinished(NO_TIMEOUT).value); + } + + public void saveAs(Path path) { + if (!connection.isRemote()) { + ArtifactSaveAsParams params = new ArtifactSaveAsParams(); + params.path = path.toString(); + channel.saveAs(params, NO_TIMEOUT); + return; + } + + Stream stream = channel.saveAsStream(NO_TIMEOUT).stream; + // java: writeToFile creates the parent directories and pipes the stream, as mkdirIfNeeded and pipe do upstream. + writeToFile(stream.stream(), path); + } + + public String failure() { + return channel.failure(NO_TIMEOUT).error; + } + public InputStream createReadStream() { return channel.stream(NO_TIMEOUT).stream.stream(); } + // java: upstream readIntoBuffer collects the 'data' chunks of the stream. byte[] readAllBytes() { final int bufLen = 1024 * 1024; byte[] buf = new byte[bufLen]; @@ -60,27 +87,4 @@ public void cancel() { public void delete() { channel.delete(NO_TIMEOUT); } - - public String failure() { - return channel.failure(NO_TIMEOUT).error; - } - - public Path pathAfterFinished() { - if (connection.isRemote()) { - throw new PlaywrightException("Path is not available when using browserType.connect(). Use download.saveAs() to save a local copy."); - } - return FileSystems.getDefault().getPath(channel.pathAfterFinished(NO_TIMEOUT).value); - } - - public void saveAs(Path path) { - if (connection.isRemote()) { - Stream stream = channel.saveAsStream(NO_TIMEOUT).stream; - writeToFile(stream.stream(), path); - return; - } - - ArtifactSaveAsParams params = new ArtifactSaveAsParams(); - params.path = path.toString(); - channel.saveAs(params, NO_TIMEOUT); - } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/CDPSessionImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/CDPSessionImpl.java index 2e785a0cc..028020441 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/CDPSessionImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/CDPSessionImpl.java @@ -23,6 +23,7 @@ import java.util.function.Consumer; +// Port of cdpSession.ts. public class CDPSessionImpl extends ChannelOwner implements CDPSession { final CDPSessionChannel channel = new CDPSessionChannel(this); @@ -31,6 +32,7 @@ protected CDPSessionImpl(ChannelOwner parent, String type, String guid, JsonObje super(parent, type, guid, initializer); } + // java: upstream subscribes in the constructor with this._channel.on(...); the Java channel dispatches events here. @Override void handleEvent(String event, JsonObject parameters) { super.handleEvent(event, parameters); @@ -47,18 +49,18 @@ void handleEvent(String event, JsonObject parameters) { } } + // java: upstream rebinds on/addListener/off/removeListener/once to the EventEmitter ones; here the raw-typed overrides + // below do that, since the raw parameter type implements CDPSession.on and overrides EventEmitter.on at once. @Override - public void onClose(Consumer handler) { - on(Events.CDPSession.CLOSE, handler); + @SuppressWarnings("rawtypes") + public void on(String event, Consumer handler) { + super.on(event, handler); } @Override - public void offClose(Consumer handler) { - off(Events.CDPSession.CLOSE, handler); - } - - public JsonObject send(String method) { - return send(method, null); + @SuppressWarnings("rawtypes") + public void off(String event, Consumer handler) { + super.off(event, handler); } @Override @@ -68,25 +70,28 @@ public JsonObject send(String method, JsonObject params, SendOptions options) { args.method = method; Double timeout = options == null || options.timeout == null ? Double.valueOf(0) : options.timeout; CDPSessionSendResult response = channel.send(args, timeout); + // java: a missing result maps to null instead of throwing. if (response == null) return null; else return response.result.getAsJsonObject(); } - // java: the raw parameter type overrides EventEmitter.on(String, Consumer) and implements CDPSession.on at once. @Override - @SuppressWarnings("rawtypes") - public void on(String event, Consumer handler) { - super.on(event, handler); + public void detach() { + channel.detach(NO_TIMEOUT); } + // java: typed close handlers and the no-options overload of the generated CDPSession interface. @Override - @SuppressWarnings("rawtypes") - public void off(String event, Consumer handler) { - super.off(event, handler); + public void onClose(Consumer handler) { + on(Events.CDPSession.CLOSE, handler); } @Override - public void detach() { - channel.detach(NO_TIMEOUT); + public void offClose(Consumer handler) { + off(Events.CDPSession.CLOSE, handler); + } + + public JsonObject send(String method) { + return send(method, null); } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/ClientHelper.java b/playwright/src/main/java/com/microsoft/playwright/impl/ClientHelper.java new file mode 100644 index 000000000..20e0cfa83 --- /dev/null +++ b/playwright/src/main/java/com/microsoft/playwright/impl/ClientHelper.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) Microsoft Corporation. + * + * Licensed 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 com.microsoft.playwright.impl; + +import java.nio.file.Path; + +// Port of clientHelper.ts. java: envObjectToArray, evaluationScript and initScriptSourceWithExposedFunctions have no Java caller. +class ClientHelper { + static String addSourceUrlToScript(String source, Path path) { + return source + "\n//# sourceURL=" + path.toString().replace("\n", ""); + } +} diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/ClockImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/ClockImpl.java index 08773c758..2962f8c54 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/ClockImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/ClockImpl.java @@ -7,6 +7,7 @@ import static com.microsoft.playwright.impl.ChannelOwner.NO_TIMEOUT; +// Port of clock.ts. class ClockImpl implements Clock { private final BrowserContextImpl browserContext; @@ -14,19 +15,7 @@ class ClockImpl implements Clock { this.browserContext = browserContext; } - @Override - public void fastForward(long ticks) { - BrowserContextClockFastForwardParams params = new BrowserContextClockFastForwardParams(); - params.ticksNumber = (double) ticks; - browserContext.channel.clockFastForward(params, NO_TIMEOUT); - } - - @Override - public void fastForward(String ticks) { - BrowserContextClockFastForwardParams params = new BrowserContextClockFastForwardParams(); - params.ticksString = ticks; - browserContext.channel.clockFastForward(params, NO_TIMEOUT); - } + // java: parseTime/parseTicks are inlined into the typed overloads (long, String, Date) of the generated Clock interface. @Override public void install(InstallOptions options) { @@ -45,17 +34,17 @@ public void install(InstallOptions options) { } @Override - public void runFor(long ticks) { - BrowserContextClockRunForParams params = new BrowserContextClockRunForParams(); + public void fastForward(long ticks) { + BrowserContextClockFastForwardParams params = new BrowserContextClockFastForwardParams(); params.ticksNumber = (double) ticks; - browserContext.channel.clockRunFor(params, NO_TIMEOUT); + browserContext.channel.clockFastForward(params, NO_TIMEOUT); } @Override - public void runFor(String ticks) { - BrowserContextClockRunForParams params = new BrowserContextClockRunForParams(); + public void fastForward(String ticks) { + BrowserContextClockFastForwardParams params = new BrowserContextClockFastForwardParams(); params.ticksString = ticks; - browserContext.channel.clockRunFor(params, NO_TIMEOUT); + browserContext.channel.clockFastForward(params, NO_TIMEOUT); } @Override @@ -84,6 +73,20 @@ public void resume() { browserContext.channel.clockResume(NO_TIMEOUT); } + @Override + public void runFor(long ticks) { + BrowserContextClockRunForParams params = new BrowserContextClockRunForParams(); + params.ticksNumber = (double) ticks; + browserContext.channel.clockRunFor(params, NO_TIMEOUT); + } + + @Override + public void runFor(String ticks) { + BrowserContextClockRunForParams params = new BrowserContextClockRunForParams(); + params.ticksString = ticks; + browserContext.channel.clockRunFor(params, NO_TIMEOUT); + } + @Override public void setFixedTime(long time) { BrowserContextClockSetFixedTimeParams params = new BrowserContextClockSetFixedTimeParams(); diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/ConsoleMessageImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/ConsoleMessageImpl.java index 6b2e0e400..43b5bbc1a 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/ConsoleMessageImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/ConsoleMessageImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of consoleMessage.ts. package com.microsoft.playwright.impl; import com.microsoft.playwright.impl.protocol.*; @@ -59,19 +60,21 @@ private ConsoleMessageImpl(PageImpl page, WorkerImpl worker, String type, String } @Override - public double timestamp() { - return timestamp; + public Worker worker() { + return worker; } - public String type() { - return type; + @Override + public PageImpl page() { + return page; } @Override - public Worker worker() { - return worker; + public String type() { + return type; } + @Override public String text() { return text; } @@ -83,11 +86,12 @@ public List args() { @Override public String location() { + // java: the public API returns a formatted string, upstream returns { url, line, column }. return url + ":" + lineNumber + ":" + columnNumber; } @Override - public PageImpl page() { - return page; + public double timestamp() { + return timestamp; } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/CredentialsImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/CredentialsImpl.java index cae934527..7e9801e11 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/CredentialsImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/CredentialsImpl.java @@ -27,37 +27,38 @@ import static com.microsoft.playwright.impl.Utils.toProtocol; import static java.util.Arrays.asList; +// Port of credentials.ts. class CredentialsImpl implements Credentials { - private final BrowserContextImpl context; + private final BrowserContextImpl browserContext; - CredentialsImpl(BrowserContextImpl context) { - this.context = context; + CredentialsImpl(BrowserContextImpl browserContext) { + this.browserContext = browserContext; } @Override public void install() { - context.channel.credentialsInstall(NO_TIMEOUT); + browserContext.channel.credentialsInstall(NO_TIMEOUT); } @Override public VirtualCredential create(String rpId, CreateOptions options) { BrowserContextCredentialsCreateParams params = toProtocol(options, BrowserContextCredentialsCreateParams.class); params.rpId = rpId; - BrowserContextCredentialsCreateResult result = context.channel.credentialsCreate(params, NO_TIMEOUT); + BrowserContextCredentialsCreateResult result = browserContext.channel.credentialsCreate(params, NO_TIMEOUT); return gson().fromJson(gson().toJsonTree(result.credential), VirtualCredential.class); } - @Override - public void delete(String id) { - BrowserContextCredentialsDeleteParams params = new BrowserContextCredentialsDeleteParams(); - params.id = id; - context.channel.credentialsDelete(params, NO_TIMEOUT); - } - @Override public List get(GetOptions options) { BrowserContextCredentialsGetParams params = toProtocol(options, BrowserContextCredentialsGetParams.class); - BrowserContextCredentialsGetResult result = context.channel.credentialsGet(params, NO_TIMEOUT); + BrowserContextCredentialsGetResult result = browserContext.channel.credentialsGet(params, NO_TIMEOUT); return asList(gson().fromJson(gson().toJsonTree(result.credentials), VirtualCredential[].class)); } + + @Override + public void delete(String id) { + BrowserContextCredentialsDeleteParams params = new BrowserContextCredentialsDeleteParams(); + params.id = id; + browserContext.channel.credentialsDelete(params, NO_TIMEOUT); + } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/DebuggerImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/DebuggerImpl.java index 10073539e..511965b4d 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/DebuggerImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/DebuggerImpl.java @@ -28,9 +28,11 @@ import static com.microsoft.playwright.impl.Serialization.gson; import static com.microsoft.playwright.impl.Utils.toProtocol; +// Port of debugger.ts. public class DebuggerImpl extends ChannelOwner implements Debugger { - private final List pausedStateChangedHandlers = new ArrayList<>(); private DebuggerPausedDetails pausedDetails; + // java: handlers of onPausedStateChanged(Runnable); upstream emits Events.Debugger.PausedStateChanged. apiCallsUpdated has no Java API. + private final List pausedStateChangedHandlers = new ArrayList<>(); final DebuggerChannel channel = new DebuggerChannel(this); @@ -38,6 +40,7 @@ public class DebuggerImpl extends ChannelOwner implements Debugger { super(parent, type, guid, initializer); } + // java: upstream subscribes in the constructor with this._channel.on(...); the Java channel dispatches events here. @Override protected void handleEvent(String event, JsonObject params) { if ("pausedStateChanged".equals(event)) { @@ -52,20 +55,7 @@ protected void handleEvent(String event, JsonObject params) { } } - @Override - public void onPausedStateChanged(Runnable handler) { - pausedStateChangedHandlers.add(handler); - } - - @Override - public void offPausedStateChanged(Runnable handler) { - pausedStateChangedHandlers.remove(handler); - } - - @Override - public DebuggerPausedDetails pausedDetails() { - return pausedDetails; - } + // java: _enable has no Java API. @Override public void requestPause() { @@ -88,4 +78,19 @@ public void runTo(Location location) { params.location = toProtocol(location, DebuggerRunToParams.DebuggerRunToParamsLocation.class); channel.runTo(params, NO_TIMEOUT); } + + @Override + public DebuggerPausedDetails pausedDetails() { + return pausedDetails; + } + + @Override + public void onPausedStateChanged(Runnable handler) { + pausedStateChangedHandlers.add(handler); + } + + @Override + public void offPausedStateChanged(Runnable handler) { + pausedStateChangedHandlers.remove(handler); + } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/DialogImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/DialogImpl.java index 5094095f4..55261e3b5 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/DialogImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/DialogImpl.java @@ -14,12 +14,12 @@ * limitations under the License. */ +// Port of dialog.ts. package com.microsoft.playwright.impl; import com.microsoft.playwright.impl.protocol.*; import com.google.gson.JsonObject; import com.microsoft.playwright.Dialog; -import com.microsoft.playwright.Page; public class DialogImpl extends ChannelOwner implements Dialog { final DialogChannel channel = new DialogChannel(this); @@ -35,38 +35,39 @@ public class DialogImpl extends ChannelOwner implements Dialog { } @Override - public void accept(String promptText) { - DialogAcceptParams params = new DialogAcceptParams(); - params.promptText = promptText; - channel.accept(params, NO_TIMEOUT); + public PageImpl page() { + return page; } @Override - public void dismiss() { - try { - channel.dismiss(NO_TIMEOUT); - } catch (TargetClosedError e) { - // Swallow TargetClosedErrors for beforeunload dialogs. - } + public String type() { + return initializer.get("type").getAsString(); } @Override - public String defaultValue() { - return initializer.get("defaultValue").getAsString(); + public String message() { + return initializer.get("message").getAsString(); } @Override - public String message() { - return initializer.get("message").getAsString(); + public String defaultValue() { + return initializer.get("defaultValue").getAsString(); } @Override - public PageImpl page() { - return page; + public void accept(String promptText) { + DialogAcceptParams params = new DialogAcceptParams(); + params.promptText = promptText; + channel.accept(params, NO_TIMEOUT); } @Override - public String type() { - return initializer.get("type").getAsString(); + public void dismiss() { + try { + channel.dismiss(NO_TIMEOUT); + } catch (TargetClosedError e) { + // java: isTargetClosedError(e) is an instanceof check on TargetClosedError. + return; + } } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/DownloadImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/DownloadImpl.java index ed6ae1810..a4bd13003 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/DownloadImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/DownloadImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of download.ts. java: url and suggestedFilename are read from the initializer. package com.microsoft.playwright.impl; import com.google.gson.JsonObject; @@ -34,6 +35,11 @@ class DownloadImpl implements Download { this.initializer = initializer; } + @Override + public Page page() { + return page; + } + @Override public String url() { return initializer.get("url").getAsString(); @@ -45,18 +51,13 @@ public String suggestedFilename() { } @Override - public void cancel() { - artifact.cancel(); - } - - @Override - public InputStream createReadStream() { - return artifact.createReadStream(); + public Path path() { + return artifact.pathAfterFinished(); } @Override - public void delete() { - artifact.delete(); + public void saveAs(Path path) { + artifact.saveAs(path); } @Override @@ -65,17 +66,17 @@ public String failure() { } @Override - public Page page() { - return page; + public InputStream createReadStream() { + return artifact.createReadStream(); } @Override - public Path path() { - return artifact.pathAfterFinished(); + public void cancel() { + artifact.cancel(); } @Override - public void saveAs(Path path) { - artifact.saveAs(path); + public void delete() { + artifact.delete(); } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/FileChooserImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/FileChooserImpl.java index 82a1fbfef..2d3e353ad 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/FileChooserImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/FileChooserImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of fileChooser.ts. package com.microsoft.playwright.impl; import com.microsoft.playwright.ElementHandle; @@ -51,6 +52,7 @@ public Page page() { return page; } + // java: overloads for the public API; each delegates to ElementHandle.setInputFiles like upstream setFiles. @Override public void setFiles(Path files, SetFilesOptions options) { setFiles(new Path[]{files}, options); diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/FileUtils.java b/playwright/src/main/java/com/microsoft/playwright/impl/FileUtils.java new file mode 100644 index 000000000..f66121fec --- /dev/null +++ b/playwright/src/main/java/com/microsoft/playwright/impl/FileUtils.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) Microsoft Corporation. + * + * Licensed 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 com.microsoft.playwright.impl; + +import com.microsoft.playwright.PlaywrightException; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +// Port of fileUtils.ts. java: fileUploadSizeLimit is inlined in Utils.checkFilePayloadSize. +class FileUtils { + // java: a failure to create the directory is reported, upstream ignores it. + static void mkdirIfNeeded(Path filePath) { + Path dir = filePath.getParent(); + if (dir != null) { + if (!Files.exists(dir)) { + try { + Files.createDirectories(dir); + } catch (IOException e) { + throw new PlaywrightException("Failed to create parent directory: " + dir, e); + } + } + } + } +} diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java index c490036ef..ee17e23f2 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/FrameImpl.java @@ -166,7 +166,7 @@ ElementHandle addScriptTagImpl(AddScriptTagOptions options) { throw new PlaywrightException("Failed to read from file", e); } String content = new String(encoded, StandardCharsets.UTF_8); - content = addSourceUrlToScript(content, options.path); + content = ClientHelper.addSourceUrlToScript(content, options.path); params.content = content; } return channel.addScriptTag(params, NO_TIMEOUT).element; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/JsonPipe.java b/playwright/src/main/java/com/microsoft/playwright/impl/JsonPipe.java index a204a45a8..bfae1770e 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/JsonPipe.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/JsonPipe.java @@ -29,17 +29,19 @@ import static com.microsoft.playwright.impl.Serialization.gson; +// Port of jsonPipe.ts. public class JsonPipe extends ChannelOwner implements Transport { - private final Queue incoming = new LinkedList<>(); - private boolean isClosed; - private String closeReason = "Browser has been closed"; - final JsonPipeChannel channel = new JsonPipeChannel(this); JsonPipe(ChannelOwner parent, String type, String guid, JsonObject initializer) { super(parent, type, guid, initializer); } + // java: the members below have no counterpart in jsonPipe.ts, they implement Transport (connect.ts upstream). + private final Queue incoming = new LinkedList<>(); + private boolean isClosed; + private String closeReason = "Browser has been closed"; + @Override public void send(JsonObject message) { checkIfClosed(); @@ -96,7 +98,6 @@ void offClose(Consumer handler) { off(Events.JsonPipe.CLOSE, handler); } - @Override protected void handleEvent(String event, JsonObject params) { if ("message".equals(event)) { diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/KeyboardImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/KeyboardImpl.java index f03b2204a..df2442cd6 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/KeyboardImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/KeyboardImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of input.ts. package com.microsoft.playwright.impl; import com.microsoft.playwright.impl.protocol.*; @@ -36,6 +37,13 @@ public void down(String key) { page.channel.keyboardDown(params, NO_TIMEOUT); } + @Override + public void up(String key) { + PageKeyboardUpParams params = new PageKeyboardUpParams(); + params.key = key; + page.channel.keyboardUp(params, NO_TIMEOUT); + } + @Override public void insertText(String text) { PageKeyboardInsertTextParams params = new PageKeyboardInsertTextParams(); @@ -43,32 +51,17 @@ public void insertText(String text) { page.channel.keyboardInsertText(params, NO_TIMEOUT); } - @Override - public void press(String key, PressOptions options) { - pressImpl(key, options); - } - - private void pressImpl(String key, PressOptions options) { - PageKeyboardPressParams params = toProtocol(options, PageKeyboardPressParams.class); - params.key = key; - page.channel.keyboardPress(params, NO_TIMEOUT); - } - @Override public void type(String text, TypeOptions options) { - typeImpl(text, options); - } - - private void typeImpl(String text, TypeOptions options) { PageKeyboardTypeParams params = toProtocol(options, PageKeyboardTypeParams.class); params.text = text; page.channel.keyboardType(params, NO_TIMEOUT); } @Override - public void up(String key) { - PageKeyboardUpParams params = new PageKeyboardUpParams(); + public void press(String key, PressOptions options) { + PageKeyboardPressParams params = toProtocol(options, PageKeyboardPressParams.class); params.key = key; - page.channel.keyboardUp(params, NO_TIMEOUT); + page.channel.keyboardPress(params, NO_TIMEOUT); } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/LocalUtils.java b/playwright/src/main/java/com/microsoft/playwright/impl/LocalUtils.java index 47d1e4f46..7c318e264 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/LocalUtils.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/LocalUtils.java @@ -26,6 +26,7 @@ import static com.microsoft.playwright.impl.Serialization.gson; +// Port of localUtils.ts. public class LocalUtils extends ChannelOwner { final LocalUtilsChannel channel = new LocalUtilsChannel(this); @@ -33,6 +34,7 @@ public class LocalUtils extends ChannelOwner { super(parent, type, guid, initializer); } + // java: devices stay the raw initializer array, DeviceDescriptor is not a Java type. JsonArray deviceDescriptors() { return initializer.getAsJsonArray("deviceDescriptors"); } @@ -50,12 +52,6 @@ void zip(Path zipFile, List entries, String stacksId, boolean appendM channel.zip(params, NO_TIMEOUT); } - void traceDiscarded(String stacksId) { - LocalUtilsTraceDiscardedParams params = new LocalUtilsTraceDiscardedParams(); - params.stacksId = stacksId; - channel.traceDiscarded(params, NO_TIMEOUT); - } - String tracingStarted(String tracesDir, String traceName) { LocalUtilsTracingStartedParams params = new LocalUtilsTracingStartedParams(); if (tracesDir != null) { @@ -65,6 +61,13 @@ String tracingStarted(String tracesDir, String traceName) { return connection.localUtils().channel.tracingStarted(params, NO_TIMEOUT).stacksId; } + void traceDiscarded(String stacksId) { + LocalUtilsTraceDiscardedParams params = new LocalUtilsTraceDiscardedParams(); + params.stacksId = stacksId; + channel.traceDiscarded(params, NO_TIMEOUT); + } + + // java: no counterpart upstream, the Java API matches globs on the driver. public Pattern globToRegex(String glob, String baseURL, boolean webSocketUrl) { LocalUtilsGlobToRegexParams params = new LocalUtilsGlobToRegexParams(); params.glob = glob; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/MouseImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/MouseImpl.java index f0f06d1b9..35955dfa6 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/MouseImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/MouseImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of input.ts. package com.microsoft.playwright.impl; import com.microsoft.playwright.impl.protocol.*; @@ -31,27 +32,11 @@ class MouseImpl implements Mouse { } @Override - public void click(double x, double y, ClickOptions options) { - PageMouseClickParams params = toProtocol(options, PageMouseClickParams.class); + public void move(double x, double y, MoveOptions options) { + PageMouseMoveParams params = toProtocol(options, PageMouseMoveParams.class); params.x = x; params.y = y; - page.channel.mouseClick(params, NO_TIMEOUT); - } - - @Override - public void dblclick(double x, double y, DblclickOptions options) { - page.withTitle("Double click", () -> dblclickImpl(x, y, options)); - } - - private void dblclickImpl(double x, double y, DblclickOptions options) { - ClickOptions clickOptions; - if (options == null) { - clickOptions = new ClickOptions(); - } else { - clickOptions = convertType(options, ClickOptions.class); - } - clickOptions.clickCount = 2; - click(x, y, clickOptions); + page.channel.mouseMove(params, NO_TIMEOUT); } @Override @@ -61,17 +46,32 @@ public void down(DownOptions options) { } @Override - public void move(double x, double y, MoveOptions options) { - PageMouseMoveParams params = toProtocol(options, PageMouseMoveParams.class); + public void up(UpOptions options) { + PageMouseUpParams params = toProtocol(options, PageMouseUpParams.class); + page.channel.mouseUp(params, NO_TIMEOUT); + } + + @Override + public void click(double x, double y, ClickOptions options) { + PageMouseClickParams params = toProtocol(options, PageMouseClickParams.class); params.x = x; params.y = y; - page.channel.mouseMove(params, NO_TIMEOUT); + page.channel.mouseClick(params, NO_TIMEOUT); } @Override - public void up(UpOptions options) { - PageMouseUpParams params = toProtocol(options, PageMouseUpParams.class); - page.channel.mouseUp(params, NO_TIMEOUT); + public void dblclick(double x, double y, DblclickOptions options) { + page.withTitle("Double click", () -> { + ClickOptions clickOptions; + if (options == null) { + // java: options is nullable, upstream defaults it to {}. + clickOptions = new ClickOptions(); + } else { + clickOptions = convertType(options, ClickOptions.class); + } + clickOptions.clickCount = 2; + click(x, y, clickOptions); + }); } @Override diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java index e02bdcd7b..aab25c781 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/PageImpl.java @@ -678,7 +678,7 @@ public AutoCloseable addInitScript(String script) { public AutoCloseable addInitScript(Path path) { try { byte[] bytes = readAllBytes(path); - String script = addSourceUrlToScript(new String(bytes, UTF_8), path); + String script = ClientHelper.addSourceUrlToScript(new String(bytes, UTF_8), path); return addInitScriptImpl(script); } catch (IOException e) { throw new PlaywrightException("Failed to read script from file", e); diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/ScreencastFrameImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/ScreencastFrameImpl.java index e70b5d51a..c067b40dc 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/ScreencastFrameImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/ScreencastFrameImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of the frame object that screencast.ts passes to onFrame (a plain object upstream). package com.microsoft.playwright.impl; import com.microsoft.playwright.ScreencastFrame; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/ScreencastImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/ScreencastImpl.java index 7dd0adba1..69cf86d5d 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/ScreencastImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/ScreencastImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of screencast.ts. java: onFrame receives a ScreencastFrame and the frame event arrives through handleScreencastFrame. package com.microsoft.playwright.impl; import com.microsoft.playwright.impl.protocol.*; @@ -99,6 +100,18 @@ public void stop() { savePath = null; } + @Override + public AutoCloseable showActions(ShowActionsOptions options) { + PageScreencastShowActionsParams params = toProtocol(options, PageScreencastShowActionsParams.class); + page.channel.screencastShowActions(params, NO_TIMEOUT); + return new DisposableStub(this::hideActions); + } + + @Override + public void hideActions() { + page.channel.screencastHideActions(NO_TIMEOUT); + } + @Override public AutoCloseable showOverlay(String html, ShowOverlayOptions options) { PageScreencastShowOverlayParams params = toProtocol(options, PageScreencastShowOverlayParams.class); @@ -119,13 +132,6 @@ public void showChapter(String title, ShowChapterOptions options) { page.channel.screencastChapter(params, NO_TIMEOUT); } - @Override - public AutoCloseable showActions(ShowActionsOptions options) { - PageScreencastShowActionsParams params = toProtocol(options, PageScreencastShowActionsParams.class); - page.channel.screencastShowActions(params, NO_TIMEOUT); - return new DisposableStub(this::hideActions); - } - @Override public void showOverlays() { PageScreencastSetOverlayVisibleParams params = new PageScreencastSetOverlayVisibleParams(); @@ -133,11 +139,6 @@ public void showOverlays() { page.channel.screencastSetOverlayVisible(params, NO_TIMEOUT); } - @Override - public void hideActions() { - page.channel.screencastHideActions(NO_TIMEOUT); - } - @Override public void hideOverlays() { PageScreencastSetOverlayVisibleParams params = new PageScreencastSetOverlayVisibleParams(); diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/SelectorsImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/SelectorsImpl.java index cbf8ff602..473429690 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/SelectorsImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/SelectorsImpl.java @@ -30,33 +30,19 @@ import static com.microsoft.playwright.impl.ChannelOwner.NO_TIMEOUT; import static java.nio.charset.StandardCharsets.UTF_8; +// Port of selectors.ts. public class SelectorsImpl extends LoggingSupport implements Selectors { - protected final List contextsForSelectors = new ArrayList<>(); protected final List selectorEngines = new ArrayList<>(); - + // java: defaults to data-testid, upstream leaves it undefined until set. String testIdAttributeName = "data-testid"; - - @Override - public void setTestIdAttribute(String attributeName) { - if (attributeName == null) { - throw new PlaywrightException("Test id attribute cannot be null"); - } - testIdAttributeName = attributeName; - for (BrowserContextImpl context : contextsForSelectors) { - try { - BrowserContextSetTestIdAttributeNameParams params = new BrowserContextSetTestIdAttributeNameParams(); - params.testIdAttributeName = attributeName; - context.sendMessageAsync("setTestIdAttributeName", params); - } catch (PlaywrightException e) { - } - } - } + protected final List contextsForSelectors = new ArrayList<>(); @Override public void register(String name, String script, RegisterOptions options) { registerImpl(name, script, options); } + // java: evaluationScript with a path, without the sourceURL suffix. @Override public void register(String name, Path path, RegisterOptions options) { byte[] buffer; @@ -86,4 +72,20 @@ private void registerImpl(String name, String script, RegisterOptions options) { } selectorEngines.add(engine); } + + @Override + public void setTestIdAttribute(String attributeName) { + if (attributeName == null) { + throw new PlaywrightException("Test id attribute cannot be null"); + } + testIdAttributeName = attributeName; + for (BrowserContextImpl context : contextsForSelectors) { + try { + BrowserContextSetTestIdAttributeNameParams params = new BrowserContextSetTestIdAttributeNameParams(); + params.testIdAttributeName = attributeName; + context.sendMessageAsync("setTestIdAttributeName", params); + } catch (PlaywrightException e) { + } + } + } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Stream.java b/playwright/src/main/java/com/microsoft/playwright/impl/Stream.java index e6939a88f..ed1fdc5c1 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Stream.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Stream.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of stream.ts. java: the Readable is an InputStream; _read becomes read(), _destroy becomes close(). package com.microsoft.playwright.impl; import com.microsoft.playwright.impl.protocol.*; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/TouchscreenImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/TouchscreenImpl.java index 71e9c1cc0..50fee64e7 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/TouchscreenImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/TouchscreenImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of input.ts. package com.microsoft.playwright.impl; import com.microsoft.playwright.impl.protocol.*; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java b/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java index fa4f92435..c3ce4a473 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/Utils.java @@ -306,19 +306,6 @@ static FilePayload toFilePayload(Path file) { return new FilePayload(file.getFileName().toString(), null, buffer); } - static void mkParentDirs(Path file) { - Path dir = file.getParent(); - if (dir != null) { - if (!Files.exists(dir)) { - try { - Files.createDirectories(dir); - } catch (IOException e) { - throw new PlaywrightException("Failed to create parent directory: " + dir, e); - } - } - } - } - /** The screenshot type for a path when no type is given, from its extension, like the Node.js client. */ static ScreenshotType screenshotTypeForPath(Path path) { String fileName = path.getFileName().toString(); @@ -335,7 +322,7 @@ static ScreenshotType screenshotTypeForPath(Path path) { } static void writeToFile(byte[] buffer, Path path) { - mkParentDirs(path); + FileUtils.mkdirIfNeeded(path); try (FileOutputStream out = new FileOutputStream(path.toFile())) { out.write(buffer); } catch (IOException e) { @@ -344,7 +331,7 @@ static void writeToFile(byte[] buffer, Path path) { } static void writeToFile(InputStream inputStream, Path path) { - mkParentDirs(path); + FileUtils.mkdirIfNeeded(path); try (FileOutputStream out = new FileOutputStream(path.toFile())) { byte[] buf = new byte[1024 * 1024]; int length; @@ -418,10 +405,6 @@ static int fromJsRegexFlags(String regexFlags) { return flags; } - static String addSourceUrlToScript(String source, Path path) { - return source + "\n//# sourceURL=" + path.toString().replace("\n", ""); - } - static JsonObject interceptionPatterns(List matchers) { JsonArray jsonPatterns = new JsonArray(); for (UrlMatcher matcher: matchers) { diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/VideoImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/VideoImpl.java index ca5e45424..a1fcd0a1f 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/VideoImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/VideoImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of video.ts. java: the video is created before its artifact is known, so the artifact is assigned later. package com.microsoft.playwright.impl; import com.microsoft.playwright.PlaywrightException; @@ -35,15 +36,10 @@ class VideoImpl implements Video { this.artifact = artifact; } - @Override - public void delete() { - if (artifact != null) - artifact.delete(); - } - @Override public Path path() { if (page.connection.isRemote()) { + // java: the message names the Java API. throw new PlaywrightException("Path is not available when using browserType.connect(). Use saveAs() to save a local copy."); } if (artifact == null) @@ -57,4 +53,10 @@ public void saveAs(Path path) { throw new PlaywrightException("Video recording has not been started."); artifact.saveAs(path); } + + @Override + public void delete() { + if (artifact != null) + artifact.delete(); + } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/WebErrorImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/WebErrorImpl.java index 95530ac05..ad04660f0 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/WebErrorImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/WebErrorImpl.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of webError.ts. package com.microsoft.playwright.impl; import com.microsoft.playwright.WebError; @@ -21,6 +22,7 @@ public class WebErrorImpl implements WebError { private final PageImpl page; + // java: the error is the message string, upstream keeps an Error. private final String error; private final WebErrorLocation location; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/WebMCPImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/WebMCPImpl.java index 639ca4cee..fedeadea2 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/WebMCPImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/WebMCPImpl.java @@ -27,6 +27,7 @@ import static com.microsoft.playwright.impl.Serialization.gson; import static com.microsoft.playwright.impl.Serialization.serializeArgument; +// Port of webmcp.ts. class WebMCPImpl implements WebMCP { private final FrameImpl frame; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/WebStorageImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/WebStorageImpl.java index 19461c1f1..e033b3040 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/WebStorageImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/WebStorageImpl.java @@ -26,6 +26,7 @@ import static com.microsoft.playwright.impl.Serialization.gson; import static java.util.Arrays.asList; +// Port of webStorage.ts. class WebStorageImpl implements WebStorage { private final PageImpl page; private final String kind; diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/WorkerImpl.java b/playwright/src/main/java/com/microsoft/playwright/impl/WorkerImpl.java index 3489ca21a..1a5f06fb3 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/WorkerImpl.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/WorkerImpl.java @@ -31,8 +31,10 @@ import static com.microsoft.playwright.impl.Serialization.*; +// Port of worker.ts. public class WorkerImpl extends ChannelOwner implements Worker { PageImpl page; + // java: no service worker or connectToWorker API, so there is no _context, _closeReason or _disconnect. final WorkerChannel channel = new WorkerChannel(this); @@ -40,50 +42,46 @@ public class WorkerImpl extends ChannelOwner implements Worker { super(parent, type, guid, initializer); } + // java: upstream subscribes in the constructor with this._channel.on(...); the Java channel dispatches events here. @Override - public void onClose(Consumer handler) { - on(Events.Worker.CLOSE, handler); - } - - @Override - public void offClose(Consumer handler) { - off(Events.Worker.CLOSE, handler); + protected void handleEvent(String event, JsonObject params) { + if ("close".equals(event)) { + if (page != null) { + page.workers.remove(this); + } + emit(Events.Worker.CLOSE, this); + } } - @Override - public void onConsole(Consumer handler) { - on(Events.Worker.CONSOLE, handler); + TargetClosedError closeErrorWithReason() { + if (page != null) { + return page.closeErrorWithReason(); + } + return new TargetClosedError(); } @Override - public void offConsole(Consumer handler) { - off(Events.Worker.CONSOLE, handler); + public String url() { + return initializer.get("url").getAsString(); } @Override - public Worker waitForClose(WaitForCloseOptions options, Runnable code) { - if (options == null) { - options = new WaitForCloseOptions(); - } - return waitForEvent(Events.Worker.CLOSE, null, options.timeout, code); + public Object evaluate(String pageFunction, Object arg) { + WorkerEvaluateExpressionParams params = new WorkerEvaluateExpressionParams(); + params.expression = pageFunction; + params.arg = serializeArgument(arg); + return deserialize(channel.evaluateExpression(params, NO_TIMEOUT).value); } @Override - public ConsoleMessage waitForConsoleMessage(WaitForConsoleMessageOptions options, Runnable code) { - if (options == null) { - options = new WaitForConsoleMessageOptions(); - } - return waitForEvent(Events.Worker.CONSOLE, options.predicate, options.timeout, code); - } - - TargetClosedError closeErrorWithReason() { - if (page != null) { - return page.closeErrorWithReason(); - } - return new TargetClosedError(); + public JSHandle evaluateHandle(String pageFunction, Object arg) { + WorkerEvaluateExpressionHandleParams params = new WorkerEvaluateExpressionHandleParams(); + params.expression = pageFunction; + params.arg = serializeArgument(arg); + return channel.evaluateExpressionHandle(params, NO_TIMEOUT).handle; } - // waitForEvent in worker.ts + // java: the predicate and timeout are passed separately and the code to run is a Runnable. private T waitForEvent(String event, Predicate predicate, Double timeout, Runnable code) { TimeoutSettings timeoutSettings = page != null ? page.timeoutSettings : new TimeoutSettings(); double timeoutMs = timeoutSettings.timeout(timeout); @@ -97,34 +95,40 @@ private T waitForEvent(String event, Predicate predicate, Double timeout, return result; } + // java: typed on/off/waitFor overloads of the generated Worker interface. @Override - public Object evaluate(String pageFunction, Object arg) { - WorkerEvaluateExpressionParams params = new WorkerEvaluateExpressionParams(); - params.expression = pageFunction; - params.arg = serializeArgument(arg); - return deserialize(channel.evaluateExpression(params, NO_TIMEOUT).value); + public void onClose(Consumer handler) { + on(Events.Worker.CLOSE, handler); } @Override - public JSHandle evaluateHandle(String pageFunction, Object arg) { - WorkerEvaluateExpressionHandleParams params = new WorkerEvaluateExpressionHandleParams(); - params.expression = pageFunction; - params.arg = serializeArgument(arg); - return channel.evaluateExpressionHandle(params, NO_TIMEOUT).handle; + public void offClose(Consumer handler) { + off(Events.Worker.CLOSE, handler); } @Override - public String url() { - return initializer.get("url").getAsString(); + public void onConsole(Consumer handler) { + on(Events.Worker.CONSOLE, handler); } @Override - protected void handleEvent(String event, JsonObject params) { - if ("close".equals(event)) { - if (page != null) { - page.workers.remove(this); - } - emit(Events.Worker.CLOSE, this); + public void offConsole(Consumer handler) { + off(Events.Worker.CONSOLE, handler); + } + + @Override + public Worker waitForClose(WaitForCloseOptions options, Runnable code) { + if (options == null) { + options = new WaitForCloseOptions(); } + return waitForEvent(Events.Worker.CLOSE, null, options.timeout, code); + } + + @Override + public ConsoleMessage waitForConsoleMessage(WaitForConsoleMessageOptions options, Runnable code) { + if (options == null) { + options = new WaitForConsoleMessageOptions(); + } + return waitForEvent(Events.Worker.CONSOLE, options.predicate, options.timeout, code); } } diff --git a/playwright/src/main/java/com/microsoft/playwright/impl/WritableStream.java b/playwright/src/main/java/com/microsoft/playwright/impl/WritableStream.java index de274de73..348d0e2ba 100644 --- a/playwright/src/main/java/com/microsoft/playwright/impl/WritableStream.java +++ b/playwright/src/main/java/com/microsoft/playwright/impl/WritableStream.java @@ -14,6 +14,7 @@ * limitations under the License. */ +// Port of writableStream.ts. java: the Writable is an OutputStream; _write becomes write(), _final becomes close(). package com.microsoft.playwright.impl; import com.microsoft.playwright.impl.protocol.*;