Skip to content
Merged
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
2 changes: 2 additions & 0 deletions packages/playwright-core/src/browserServerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { serverSideCallMetadata } from './server/instrumentation';
import { createPlaywright } from './server/playwright';
import { createGuid } from './server/utils/crypto';
import { rewriteErrorMessage } from './utils/isomorphic/stackTrace';
import { DEFAULT_PLAYWRIGHT_LAUNCH_TIMEOUT } from './utils/isomorphic/time';
import { ws } from './utilsBundle';

import type { BrowserServer, BrowserServerLauncher } from './client/browserType';
Expand Down Expand Up @@ -48,6 +49,7 @@ export class BrowserServerLauncherImpl implements BrowserServerLauncher {
ignoreDefaultArgs: Array.isArray(options.ignoreDefaultArgs) ? options.ignoreDefaultArgs : undefined,
ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs),
env: options.env ? envObjectToArray(options.env) : undefined,
timeout: options.timeout ?? DEFAULT_PLAYWRIGHT_LAUNCH_TIMEOUT,
}, toProtocolLogger(options.logger)).catch(e => {
const log = helper.formatBrowserLogs(metadata.log);
rewriteErrorMessage(e, `${e.message} Failed to launch browser.${log}`);
Expand Down
46 changes: 22 additions & 24 deletions packages/playwright-core/src/client/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class Android extends ChannelOwner<channels.AndroidChannel> implements ap

setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout }).catch(() => {});
}

async devices(options: { port?: number } = {}): Promise<AndroidDevice[]> {
Expand All @@ -69,7 +68,7 @@ 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 = { wsEndpoint, headers, slowMo: options.slowMo, timeout: options.timeout };
const connectParams: channels.LocalUtilsConnectParams = { wsEndpoint, headers, slowMo: options.slowMo, timeout: options.timeout || 0 };
const connection = await connectOverWebSocket(this._connection, connectParams);

let device: AndroidDevice;
Expand Down Expand Up @@ -133,7 +132,6 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel> i

setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout }).catch(() => {});
}

serial(): string {
Expand Down Expand Up @@ -162,49 +160,49 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel> i
return await this.waitForEvent('webview', { ...options, predicate });
}

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

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

async press(selector: api.AndroidSelector, key: api.AndroidKey, options?: types.TimeoutOptions) {
async press(selector: api.AndroidSelector, key: api.AndroidKey, options: types.TimeoutOptions = {}) {
await this.tap(selector, options);
await this.input.press(key);
}

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

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

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

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

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

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

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

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

async info(selector: api.AndroidSelector): Promise<api.AndroidElementInfo> {
Expand Down
3 changes: 1 addition & 2 deletions packages/playwright-core/src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
this._isChromium = this._browser?._name === 'chromium';
this.tracing = Tracing.from(initializer.tracing);
this.request = APIRequestContext.from(initializer.requestContext);
this.request._timeoutSettings = this._timeoutSettings;
Comment thread
dgozman marked this conversation as resolved.
this.clock = new Clock(this);

this._channel.on('bindingCall', ({ binding }) => this._onBinding(BindingCall.from(binding)));
Expand Down Expand Up @@ -245,12 +246,10 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>

setDefaultNavigationTimeout(timeout: number | undefined) {
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
this._channel.setDefaultNavigationTimeoutNoReply({ timeout }).catch(() => {});
}

setDefaultTimeout(timeout: number | undefined) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout }).catch(() => {});
}

browser(): Browser | null {
Expand Down
7 changes: 5 additions & 2 deletions packages/playwright-core/src/client/browserType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { headersObjectToArray } from '../utils/isomorphic/headers';
import { monotonicTime } from '../utils/isomorphic/time';
import { raceAgainstDeadline } from '../utils/isomorphic/timeoutRunner';
import { connectOverWebSocket } from './webSocket';
import { TimeoutSettings } from './timeoutSettings';

import type { Playwright } from './playwright';
import type { ConnectOptions, LaunchOptions, LaunchPersistentContextOptions, LaunchServerOptions, Logger } from './types';
Expand Down Expand Up @@ -73,6 +74,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
ignoreDefaultArgs: Array.isArray(options.ignoreDefaultArgs) ? options.ignoreDefaultArgs : undefined,
ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs),
env: options.env ? envObjectToArray(options.env) : undefined,
timeout: new TimeoutSettings(this._platform).launchTimeout(options),
};
return await this._wrapApiCall(async () => {
const browser = Browser.from((await this._channel.launch(launchOptions)).browser);
Expand Down Expand Up @@ -100,6 +102,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
env: options.env ? envObjectToArray(options.env) : undefined,
channel: options.channel,
userDataDir: (this._platform.path().isAbsolute(userDataDir) || !userDataDir) ? userDataDir : this._platform.path().resolve(userDataDir),
timeout: new TimeoutSettings(this._platform).launchTimeout(options),
};
return await this._wrapApiCall(async () => {
const result = await this._channel.launchPersistentContext(persistentParams);
Expand Down Expand Up @@ -128,7 +131,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
headers,
exposeNetwork: params.exposeNetwork ?? params._exposeNetwork,
slowMo: params.slowMo,
timeout: params.timeout,
timeout: params.timeout || 0,
};
if ((params as any).__testHookRedirectPortForwarding)
connectParams.socksProxyRedirectPortForTest = (params as any).__testHookRedirectPortForwarding;
Expand Down Expand Up @@ -188,7 +191,7 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
endpointURL,
headers,
slowMo: params.slowMo,
timeout: params.timeout
timeout: new TimeoutSettings(this._platform).timeout(params),
});
const browser = Browser.from(result.browser);
this._didLaunchBrowser(browser, {}, params.logger);
Expand Down
2 changes: 2 additions & 0 deletions packages/playwright-core/src/client/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ElectronOptions = Omit<channels.ElectronLaunchOptions, 'env'|'extraHTTPHead
recordHar?: BrowserContextOptions['recordHar'],
colorScheme?: 'dark' | 'light' | 'no-preference' | null,
acceptDownloads?: boolean,
timeout?: number,
};

type ElectronAppType = typeof import('electron');
Expand All @@ -56,6 +57,7 @@ export class Electron extends ChannelOwner<channels.ElectronChannel> implements
...await prepareBrowserContextParams(this._platform, options),
env: envObjectToArray(options.env ? options.env : this._platform.env),
tracesDir: options.tracesDir,
timeout: new TimeoutSettings(this._platform).launchTimeout(options),
};
const app = ElectronApplication.from((await this._channel.launch(params)).electronApplication);
app._context._setOptions(params, options);
Expand Down
Loading