Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 33 additions & 29 deletions packages/playwright-core/src/client/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Android extends ChannelOwner<channels.AndroidChannel> implements ap
}

async devices(options: { port?: number } = {}): Promise<AndroidDevice[]> {
const { devices } = await this._channel.devices(options, undefined);
const { devices } = await this._channel.devices(options, { signal: undefined, timeout: 0 });
return devices.map(d => AndroidDevice.from(d));
}

Expand All @@ -71,8 +71,8 @@ export class Android extends ChannelOwner<channels.AndroidChannel> implements ap
return await this._wrapApiCall(async () => {
const deadline = options.timeout ? monotonicTime() + options.timeout : 0;
const headers = { 'x-playwright-browser': 'android', ...options.headers };
const connectParams: channels.LocalUtilsConnectParams = { endpoint, headers, slowMo: options.slowMo, timeout: options.timeout || 0 };
const connection = await connectToEndpoint(this._connection, connectParams);
const connectParams: channels.LocalUtilsConnectParams = { endpoint, headers, slowMo: options.slowMo };
const connection = await connectToEndpoint(this._connection, connectParams, options.timeout || 0);

let device: AndroidDevice;
connection.on('close', () => {
Expand Down Expand Up @@ -139,6 +139,10 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel> i
this._timeoutSettings.setDefaultTimeout(timeout);
}

_timeout(options?: types.TimeoutOptions): channels.CommandOptions {
return { signal: options?.signal, timeout: this._timeoutSettings.timeout(options || {}) };
}

serial(): string {
return this._initializer.serial;
}
Expand Down Expand Up @@ -166,11 +170,11 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel> i
}

async wait(selector: api.AndroidSelector, options: { state?: 'gone' } & types.TimeoutOptions = {}) {
await this._channel.wait({ androidSelector: toSelectorChannel(selector), ...options, timeout: this._timeoutSettings.timeout(options) }, options.signal);
await this._channel.wait({ androidSelector: toSelectorChannel(selector), ...options }, this._timeout(options));
}

async fill(selector: api.AndroidSelector, text: string, options: types.TimeoutOptions = {}) {
await this._channel.fill({ androidSelector: toSelectorChannel(selector), text, ...options, timeout: this._timeoutSettings.timeout(options) }, options.signal);
await this._channel.fill({ androidSelector: toSelectorChannel(selector), text, ...options }, this._timeout(options));
}

async press(selector: api.AndroidSelector, key: api.AndroidKey, options: types.TimeoutOptions = {}) {
Expand All @@ -179,43 +183,43 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel> i
}

async tap(selector: api.AndroidSelector, options: { duration?: number } & types.TimeoutOptions = {}) {
await this._channel.tap({ androidSelector: toSelectorChannel(selector), ...options, timeout: this._timeoutSettings.timeout(options) }, options.signal);
await this._channel.tap({ androidSelector: toSelectorChannel(selector), ...options }, this._timeout(options));
}

async drag(selector: api.AndroidSelector, dest: types.Point, options: SpeedOptions & types.TimeoutOptions = {}) {
await this._channel.drag({ androidSelector: toSelectorChannel(selector), dest, ...options, timeout: this._timeoutSettings.timeout(options) }, options.signal);
await this._channel.drag({ androidSelector: toSelectorChannel(selector), dest, ...options }, this._timeout(options));
}

async fling(selector: api.AndroidSelector, direction: Direction, options: SpeedOptions & types.TimeoutOptions = {}) {
await this._channel.fling({ androidSelector: toSelectorChannel(selector), direction, ...options, timeout: this._timeoutSettings.timeout(options) }, options.signal);
await this._channel.fling({ androidSelector: toSelectorChannel(selector), direction, ...options }, this._timeout(options));
}

async longTap(selector: api.AndroidSelector, options: types.TimeoutOptions = {}) {
await this._channel.longTap({ androidSelector: toSelectorChannel(selector), ...options, timeout: this._timeoutSettings.timeout(options) }, options.signal);
await this._channel.longTap({ androidSelector: toSelectorChannel(selector), ...options }, this._timeout(options));
}

async pinchClose(selector: api.AndroidSelector, percent: number, options: SpeedOptions & types.TimeoutOptions = {}) {
await this._channel.pinchClose({ androidSelector: toSelectorChannel(selector), percent, ...options, timeout: this._timeoutSettings.timeout(options) }, options.signal);
await this._channel.pinchClose({ androidSelector: toSelectorChannel(selector), percent, ...options }, this._timeout(options));
}

async pinchOpen(selector: api.AndroidSelector, percent: number, options: SpeedOptions & types.TimeoutOptions = {}) {
await this._channel.pinchOpen({ androidSelector: toSelectorChannel(selector), percent, ...options, timeout: this._timeoutSettings.timeout(options) }, options.signal);
await this._channel.pinchOpen({ androidSelector: toSelectorChannel(selector), percent, ...options }, this._timeout(options));
}

async scroll(selector: api.AndroidSelector, direction: Direction, percent: number, options: SpeedOptions & types.TimeoutOptions = {}) {
await this._channel.scroll({ androidSelector: toSelectorChannel(selector), direction, percent, ...options, timeout: this._timeoutSettings.timeout(options) }, options.signal);
await this._channel.scroll({ androidSelector: toSelectorChannel(selector), direction, percent, ...options }, this._timeout(options));
}

async swipe(selector: api.AndroidSelector, direction: Direction, percent: number, options: SpeedOptions & types.TimeoutOptions = {}) {
await this._channel.swipe({ androidSelector: toSelectorChannel(selector), direction, percent, ...options, timeout: this._timeoutSettings.timeout(options) }, options.signal);
await this._channel.swipe({ androidSelector: toSelectorChannel(selector), direction, percent, ...options }, this._timeout(options));
}

async info(selector: api.AndroidSelector): Promise<api.AndroidElementInfo> {
return (await this._channel.info({ androidSelector: toSelectorChannel(selector) }, undefined)).info;
return (await this._channel.info({ androidSelector: toSelectorChannel(selector) }, { signal: undefined, timeout: 0 })).info;
}

async screenshot(options: { path?: string } = {}): Promise<Buffer> {
const { binary } = await this._channel.screenshot({}, undefined);
const { binary } = await this._channel.screenshot({}, { signal: undefined, timeout: 0 });
if (options.path)
await fs.promises.writeFile(options.path, binary);
return binary;
Expand All @@ -230,7 +234,7 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel> i
if (this._shouldCloseConnectionOnClose)
this._connection.close();
else
await this._channel.close({}, undefined);
await this._channel.close({}, { signal: undefined, timeout: 0 });
} catch (e) {
if (isTargetClosedError(e))
return;
Expand All @@ -243,25 +247,25 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel> i
}

async shell(command: string): Promise<Buffer> {
const { result } = await this._channel.shell({ command }, undefined);
const { result } = await this._channel.shell({ command }, { signal: undefined, timeout: 0 });
return result;
}

async open(command: string): Promise<AndroidSocket> {
return AndroidSocket.from((await this._channel.open({ command }, undefined)).socket);
return AndroidSocket.from((await this._channel.open({ command }, { signal: undefined, timeout: 0 })).socket);
}

async installApk(file: string | Buffer, options?: { args: string[] }): Promise<void> {
await this._channel.installApk({ file: await loadFile(file), args: options && options.args }, undefined);
await this._channel.installApk({ file: await loadFile(file), args: options && options.args }, { signal: undefined, timeout: 0 });
}

async push(file: string | Buffer, path: string, options?: { mode: number }): Promise<void> {
await this._channel.push({ file: await loadFile(file), path, mode: options ? options.mode : undefined }, undefined);
await this._channel.push({ file: await loadFile(file), path, mode: options ? options.mode : undefined }, { signal: undefined, timeout: 0 });
}

async launchBrowser(options: types.BrowserContextOptions & { pkg?: string } = {}): Promise<BrowserContext> {
const contextOptions = await prepareBrowserContextParams(options);
const result = await this._channel.launchBrowser(contextOptions, undefined);
const result = await this._channel.launchBrowser(contextOptions, { signal: undefined, timeout: 0 });
const context = BrowserContext.from(result.context);
const selectors = this._android._playwright.selectors;
selectors._contextsForSelectors.add(context);
Expand Down Expand Up @@ -299,11 +303,11 @@ export class AndroidSocket extends ChannelOwner<channels.AndroidSocketChannel> i
}

async write(data: Buffer): Promise<void> {
await this._channel.write({ data }, undefined);
await this._channel.write({ data }, { signal: undefined, timeout: 0 });
}

async close(): Promise<void> {
await this._channel.close({}, undefined);
await this._channel.close({}, { signal: undefined, timeout: 0 });
}

async [Symbol.asyncDispose]() {
Expand All @@ -325,23 +329,23 @@ export class AndroidInput implements api.AndroidInput {
}

async type(text: string) {
await this._device._channel.inputType({ text }, undefined);
await this._device._channel.inputType({ text }, { signal: undefined, timeout: 0 });
}

async press(key: api.AndroidKey) {
await this._device._channel.inputPress({ key }, undefined);
await this._device._channel.inputPress({ key }, { signal: undefined, timeout: 0 });
}

async tap(point: types.Point) {
await this._device._channel.inputTap({ point }, undefined);
await this._device._channel.inputTap({ point }, { signal: undefined, timeout: 0 });
}

async swipe(from: types.Point, segments: types.Point[], steps: number) {
await this._device._channel.inputSwipe({ segments, steps }, undefined);
await this._device._channel.inputSwipe({ segments, steps }, { signal: undefined, timeout: 0 });
}

async drag(from: types.Point, to: types.Point, steps: number) {
await this._device._channel.inputDrag({ from, to, steps }, undefined);
await this._device._channel.inputDrag({ from, to, steps }, { signal: undefined, timeout: 0 });
}
}

Expand Down Expand Up @@ -425,7 +429,7 @@ export class AndroidWebView extends EventEmitter implements api.AndroidWebView {
}

private async _fetchPage(): Promise<Page> {
const { context } = await this._device._channel.connectToWebView({ socketName: this._data.socketName }, undefined);
const { context } = await this._device._channel.connectToWebView({ socketName: this._data.socketName }, { signal: undefined, timeout: 0 });
return BrowserContext.from(context).pages()[0];
}
}
14 changes: 7 additions & 7 deletions packages/playwright-core/src/client/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ export class Artifact extends ChannelOwner<channels.ArtifactChannel> {
async pathAfterFinished(): Promise<string> {
if (this._connection.isRemote())
throw new Error(`Path is not available when connecting remotely. Use saveAs() to save a local copy.`);
return (await this._channel.pathAfterFinished({}, undefined)).value;
return (await this._channel.pathAfterFinished({}, { signal: undefined, timeout: 0 })).value;
}

async saveAs(path: string): Promise<void> {
if (!this._connection.isRemote()) {
await this._channel.saveAs({ path }, undefined);
await this._channel.saveAs({ path }, { signal: undefined, timeout: 0 });
return;
}

const result = await this._channel.saveAsStream({}, undefined);
const result = await this._channel.saveAsStream({}, { signal: undefined, timeout: 0 });
const stream = Stream.from(result.stream);
await mkdirIfNeeded(path);
await new Promise((resolve, reject) => {
Expand All @@ -51,11 +51,11 @@ export class Artifact extends ChannelOwner<channels.ArtifactChannel> {
}

async failure(): Promise<string | null> {
return (await this._channel.failure({}, undefined)).error || null;
return (await this._channel.failure({}, { signal: undefined, timeout: 0 })).error || null;
}

async createReadStream(): Promise<Readable> {
const result = await this._channel.stream({}, undefined);
const result = await this._channel.stream({}, { signal: undefined, timeout: 0 });
const stream = Stream.from(result.stream);
return stream.stream();
}
Expand All @@ -75,10 +75,10 @@ export class Artifact extends ChannelOwner<channels.ArtifactChannel> {
}

async cancel(): Promise<void> {
return await this._channel.cancel({}, undefined);
return await this._channel.cancel({}, { signal: undefined, timeout: 0 });
}

async delete(): Promise<void> {
return await this._channel.delete({}, undefined);
return await this._channel.delete({}, { signal: undefined, timeout: 0 });
}
}
16 changes: 8 additions & 8 deletions packages/playwright-core/src/client/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
for (const page of context.pages())
page._onClose();
context._onClose();
await this._channel.disconnectFromReusedContext({ reason }, undefined);
await this._channel.disconnectFromReusedContext({ reason }, { signal: undefined, timeout: 0 });
}

async _innerNewContext(userOptions: BrowserContextOptions = {}, forReuse: boolean): Promise<BrowserContext> {
const options = this._browserType._playwright.selectors._withSelectorOptions(userOptions);
await this._instrumentation.runBeforeCreateBrowserContext(options);
const contextOptions = await prepareBrowserContextParams(options);
const response = forReuse ? await this._channel.newContextForReuse(contextOptions, undefined) : await this._channel.newContext(contextOptions, undefined);
const response = forReuse ? await this._channel.newContextForReuse(contextOptions, { signal: undefined, timeout: 0 }) : await this._channel.newContext(contextOptions, { signal: undefined, timeout: 0 });
const context = BrowserContext.from(response.context);
if (forReuse)
context._forReuse = true;
Expand Down Expand Up @@ -132,12 +132,12 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
}

async bind(title: string, options: { workspaceDir?: string, metadata?: Record<string, any>, host?: string, port?: number } = {}): Promise<{ endpoint: string }> {
const { endpoint } = await this._channel.startServer({ title, ...options }, undefined);
const { endpoint } = await this._channel.startServer({ title, ...options }, { signal: undefined, timeout: 0 });
return { endpoint };
}

async unbind(): Promise<void> {
await this._channel.stopServer({}, undefined);
await this._channel.stopServer({}, { signal: undefined, timeout: 0 });
}

async newPage(options: BrowserContextOptions = {}): Promise<Page> {
Expand All @@ -155,16 +155,16 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
}

async newBrowserCDPSession(): Promise<api.CDPSession> {
return CDPSession.from((await this._channel.newBrowserCDPSession({}, undefined)).session);
return CDPSession.from((await this._channel.newBrowserCDPSession({}, { signal: undefined, timeout: 0 })).session);
}

async startTracing(page?: Page, options: { path?: string; screenshots?: boolean; categories?: string[]; } = {}) {
this._path = options.path;
await this._channel.startTracing({ ...options, page: page ? page._channel : undefined }, undefined);
await this._channel.startTracing({ ...options, page: page ? page._channel : undefined }, { signal: undefined, timeout: 0 });
}

async stopTracing(): Promise<Buffer> {
const artifact = Artifact.from((await this._channel.stopTracing({}, undefined)).artifact);
const artifact = Artifact.from((await this._channel.stopTracing({}, { signal: undefined, timeout: 0 })).artifact);
const buffer = await artifact.readIntoBuffer();
await artifact.delete();
if (this._path) {
Expand All @@ -185,7 +185,7 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
if (this._shouldCloseConnectionOnClose)
this._connection.close();
else
await this._channel.close(options, undefined);
await this._channel.close(options, { signal: undefined, timeout: 0 });
await this._closedPromise;
} catch (e) {
if (isTargetClosedError(e))
Expand Down
Loading
Loading