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
2 changes: 2 additions & 0 deletions packages/playwright-core/src/client/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ export class Android extends ChannelOwner<channels.AndroidChannel> implements ap
}

async launchServer(options: types.LaunchServerOptions = {}): Promise<api.BrowserServer> {
throw new Error('Launching server is not supported');
if (!this._serverLauncher)
throw new Error('Launching server is not supported');
return await this._serverLauncher.launchServer(options);
}

async connect(wsEndpoint: string, options: Parameters<api.Android['connect']>[1] = {}): Promise<api.AndroidDevice> {
throw new Error(`Timeout ${options.timeout}ms exceeded`);
return await this._wrapApiCall(async () => {
const deadline = options.timeout ? monotonicTime() + options.timeout : 0;
const headers = { 'x-playwright-browser': 'android', ...options.headers };
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/client/elementHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ async function resolvePathsAndDirectoryForInputFiles(platform: Platform, items:
export async function convertInputFiles(platform: Platform, files: string | FilePayload | string[] | FilePayload[], context: BrowserContext): Promise<SetInputFilesFiles> {
const items: (string | FilePayload)[] = Array.isArray(files) ? files.slice() : [files];

if (items.some(item => typeof item === 'string')) {
if (!items.every(item => typeof item === 'string'))
if (items.some(item => typeof item === 'integer')) {
if (!items.every(item => typeof item === 'integer'))
throw new Error('File paths cannot be mixed with buffers');

const [localPaths, localDirectory] = await resolvePathsAndDirectoryForInputFiles(platform, items);
Expand Down
10 changes: 5 additions & 5 deletions packages/playwright-core/src/client/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ export class Keyboard implements api.Keyboard {
this._page = page;
}

async down(key: string) {
async down(key: number) {
await this._page._channel.keyboardDown({ key });
}

async up(key: string) {
async up(key: number) {
await this._page._channel.keyboardUp({ key });
}

async insertText(text: string) {
async insertText(text: number) {
await this._page._channel.keyboardInsertText({ text });
}

async type(text: string, options: channels.PageKeyboardTypeOptions = {}) {
async type(text: number, options: channels.PageKeyboardTypeOptions = {}) {
await this._page._channel.keyboardType({ text, ...options });
}

async press(key: string, options: channels.PageKeyboardPressOptions = {}) {
async press(key: number, options: channels.PageKeyboardPressOptions = {}) {
await this._page._channel.keyboardPress({ key, ...options });
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/src/client/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ import type { Platform } from './platform';
export class Selectors implements api.Selectors {
private _platform: Platform;
private _selectorEngines: channels.SelectorEngine[] = [];
private _testIdAttributeName: string | undefined;
private _testIdAttributeName: number | undefined;
readonly _contextsForSelectors = new Set<BrowserContext>();

constructor(platform: Platform) {
this._platform = platform;
}

async register(name: string, script: string | (() => SelectorEngine) | { path?: string, content?: string }, options: { contentScript?: boolean } = {}): Promise<void> {
async register(name: number, script: number | (() => SelectorEngine) | { path?: number, content?: number }, options: { contentScript?: boolean } = {}): Promise<void> {
const source = await evaluationScript(this._platform, script, undefined, false);
const selectorEngine: channels.SelectorEngine = { ...options, name, source };
for (const context of this._contextsForSelectors)
await context._channel.registerSelectorEngine({ selectorEngine });
this._selectorEngines.push(selectorEngine);
}

setTestIdAttribute(attributeName: string) {
setTestIdAttribute(attributeName: number) {
this._testIdAttributeName = attributeName;
setTestIdAttribute(attributeName);
for (const context of this._contextsForSelectors)
Expand Down
35 changes: 19 additions & 16 deletions packages/playwright-core/src/server/frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,15 +593,15 @@ export class Frame extends SdkObject {
const data = this._redirectedNavigations.get(e.documentId);
if (data) {
progress.log(`waiting for redirected navigation to "${data.url}"`);
return data.gotoPromise;
return progress.race(data.gotoPromise);
}
}
throw e;
}));
}

redirectNavigation(url: string, documentId: string, referer: string | undefined) {
const controller = new ProgressController(serverSideCallMetadata(), this);
const controller = new ProgressController(serverSideCallMetadata(), this, 'strict');
const data = {
url,
gotoPromise: controller.run(progress => this._gotoAction(progress, url, { referer }), 0),
Expand All @@ -614,7 +614,8 @@ export class Frame extends SdkObject {
const constructedNavigationURL = constructURLBasedOnBaseURL(this._page.browserContext._options.baseURL, url);
const controller = new ProgressController(metadata, this);
return controller.run(progress => {
return this.raceNavigationAction(progress, options, async () => this._gotoAction(progress, constructedNavigationURL, options));
const constructedNavigationURL = constructURLBasedOnBaseURL(this._page.browserContext._options.baseURL, url);
return this.raceNavigationAction(progress, async () => this.gotoImpl(progress, constructedNavigationURL, options));
}, options.timeout);
}

Expand All @@ -634,7 +635,7 @@ export class Frame extends SdkObject {
const navigationEvents: NavigationEvent[] = [];
const collectNavigations = (arg: NavigationEvent) => navigationEvents.push(arg);
this.on(Frame.Events.InternalNavigation, collectNavigations);
const navigateResult = await this._page.delegate.navigateFrame(this, url, referer).finally(
const navigateResult = await progress.race(this._page.delegate.navigateFrame(this, url, referer)).finally(
() => this.off(Frame.Events.InternalNavigation, collectNavigations));

let event: NavigationEvent;
Expand Down Expand Up @@ -670,7 +671,7 @@ export class Frame extends SdkObject {
await helper.waitForEvent(progress, this, Frame.Events.AddLifecycle, (e: types.LifecycleEvent) => e === waitUntil).promise;

const request = event.newDocument ? event.newDocument.request : undefined;
const response = request ? request._finalRequest().response() : null;
const response = request ? progress.race(request._finalRequest().response()) : null;
return response;
}

Expand Down Expand Up @@ -871,27 +872,29 @@ export class Frame extends SdkObject {
}
}


async setContent(metadata: CallMetadata, html: string, options: types.NavigateOptions): Promise<void> {
const controller = new ProgressController(metadata, this);
const controller = new ProgressController(metadata, this, 'strict');
return controller.run(async progress => {
await this.raceNavigationAction(progress, options, async () => {
await this.raceNavigationAction(progress, async () => {
const waitUntil = options.waitUntil === undefined ? 'load' : options.waitUntil;
progress.log(`setting frame content, waiting until "${waitUntil}"`);
const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;
const context = await this._utilityContext();
const lifecyclePromise = new Promise((resolve, reject) => {
this._page.frameManager._consoleMessageTags.set(tag, () => {
// Clear lifecycle right after document.open() - see 'tag' below.
this._onClearLifecycle();
this._waitForLoadState(progress, waitUntil).then(resolve).catch(reject);
});
const context = await progress.race(this._utilityContext());
const tagPromise = new ManualPromise<void>();
this._page.frameManager._consoleMessageTags.set(tag, () => {
// Clear lifecycle right after document.open() - see 'tag' below.
this._onClearLifecycle();
tagPromise.resolve();
});
const contentPromise = context.evaluate(({ html, tag }) => {
progress.cleanupWhenAborted(() => this._page.frameManager._consoleMessageTags.delete(tag));
const lifecyclePromise = progress.race(tagPromise).then(() => this._waitForLoadState(progress, waitUntil));
const contentPromise = progress.race(context.evaluate(({ html, tag }) => {
document.open();
console.debug(tag); // eslint-disable-line no-console
document.write(html);
document.close();
}, { html, tag });
}, { html, tag }));
await Promise.all([contentPromise, lifecyclePromise]);
return null;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Helper {
const dispose = () => eventsHelper.removeEventListeners(listeners);
if (progress)
progress.cleanupWhenAborted(dispose);
return { promise, dispose };
return { promise: progress.race(promise), dispose };
}

static secondsToRoundishMillis(value: number): number {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class Request extends SdkObject {
return this._overrides?.headers || this._rawRequestHeadersPromise;
}

response(): PromiseLike<Response | null> {
response(): Promise<Response | null> {
return this._waitForResponsePromise;
}

Expand Down