Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
afed224
refactor(artifact): follow artifact.ts
yury-s Nov 18, 2026
3fad560
refactor(stream): follow stream.ts
yury-s Nov 18, 2026
77fac88
refactor(writable-stream): follow writableStream.ts
yury-s Nov 18, 2026
e363eb6
refactor(download): follow download.ts
yury-s Nov 18, 2026
d2c06dd
refactor(video): follow video.ts
yury-s Nov 18, 2026
babc976
refactor(screencast): follow screencast.ts
yury-s Nov 18, 2026
9211a02
refactor(consoleMessage): follow consoleMessage.ts
yury-s Nov 18, 2026
a370858
refactor(dialog): follow dialog.ts
yury-s Nov 18, 2026
c99943b
refactor(fileChooser): follow fileChooser.ts
yury-s Nov 18, 2026
5e771b1
refactor(webError): follow webError.ts
yury-s Nov 18, 2026
fe31508
refactor(worker): follow worker.ts
yury-s Nov 18, 2026
232b061
refactor(cdpSession): follow cdpSession.ts
yury-s Nov 18, 2026
6f16eab
refactor(debugger): follow debugger.ts
yury-s Nov 18, 2026
d386ed4
refactor(clock): follow clock.ts
yury-s Nov 18, 2026
6d428c0
refactor(webStorage): follow webStorage.ts
yury-s Nov 18, 2026
522469b
refactor(credentials): follow credentials.ts
yury-s Nov 18, 2026
591e59c
refactor(webmcp): follow webmcp.ts
yury-s Nov 18, 2026
6e7ec8c
refactor(input): follow input.ts
yury-s Nov 18, 2026
f89bb34
refactor(localUtils): follow localUtils.ts
yury-s Nov 18, 2026
1de6f49
refactor(jsonPipe): follow jsonPipe.ts
yury-s Nov 18, 2026
5f6643d
refactor(selectors): follow selectors.ts
yury-s Nov 18, 2026
ca8750e
refactor(clientHelper): follow clientHelper.ts and fileUtils.ts
yury-s Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

// Port of artifact.ts.
package com.microsoft.playwright.impl;

import com.microsoft.playwright.impl.protocol.*;
Expand All @@ -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];
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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<CDPSession> handler) {
on(Events.CDPSession.CLOSE, handler);
@SuppressWarnings("rawtypes")
public void on(String event, Consumer handler) {
super.on(event, handler);
}

@Override
public void offClose(Consumer<CDPSession> 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
Expand All @@ -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<CDPSession> handler) {
on(Events.CDPSession.CLOSE, handler);
}

@Override
public void detach() {
channel.detach(NO_TIMEOUT);
public void offClose(Consumer<CDPSession> handler) {
off(Events.CDPSession.CLOSE, handler);
}

public JsonObject send(String method) {
return send(method, null);
}
}
Original file line number Diff line number Diff line change
@@ -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", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,15 @@

import static com.microsoft.playwright.impl.ChannelOwner.NO_TIMEOUT;

// Port of clock.ts.
class ClockImpl implements Clock {
private final BrowserContextImpl browserContext;

ClockImpl(BrowserContextImpl browserContext) {
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) {
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

// Port of consoleMessage.ts.
package com.microsoft.playwright.impl;

import com.microsoft.playwright.impl.protocol.*;
Expand Down Expand Up @@ -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;
}
Expand All @@ -83,11 +86,12 @@ public List<JSHandle> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<VirtualCredential> 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);
}
}
Loading
Loading