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: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export default [
},
languageOptions: languageOptionsWithTsConfig,
rules: {
"progress/await-must-use-progress": "warn",
"progress/await-must-use-progress": "error",
},
},
{
Expand Down
14 changes: 7 additions & 7 deletions packages/playwright-core/src/server/android/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export class AndroidDevice extends SdkObject {

async launchBrowser(progress: Progress, pkg: string = 'com.android.chrome', options: channels.AndroidDeviceLaunchBrowserParams): Promise<BrowserContext> {
debug('pw:android')('Force-stopping', pkg);
await this._backend.runCommand(`shell:am force-stop ${pkg}`);
await progress.race(this._backend.runCommand(`shell:am force-stop ${pkg}`));
const socketName = isUnderTest() ? 'webview_devtools_remote_playwright_test' : ('playwright_' + createGuid() + '_devtools_remote');
const commandLine = this._defaultArgs(options, socketName).join(' ');
debug('pw:android')('Starting', pkg, commandLine);
Expand Down Expand Up @@ -394,21 +394,21 @@ export class AndroidDevice extends SdkObject {

async push(progress: Progress, content: Buffer, path: string, mode = 0o644): Promise<void> {
const socket = await this._open(progress, `sync:`);
const sendHeader = async (command: string, length: number) => {
const sendHeader = async (progress: Progress, command: string, length: number) => {
const buffer = Buffer.alloc(command.length + 4);
buffer.write(command, 0);
buffer.writeUInt32LE(length, command.length);
await progress.race(socket.write(buffer));
};
const send = async (command: string, data: Buffer) => {
await sendHeader(command, data.length);
const send = async (progress: Progress, command: string, data: Buffer) => {
await sendHeader(progress, command, data.length);
await progress.race(socket.write(data));
};
await send('SEND', Buffer.from(`${path},${mode}`));
await send(progress, 'SEND', Buffer.from(`${path},${mode}`));
const maxChunk = 65535;
for (let i = 0; i < content.length; i += maxChunk)
await send('DATA', content.slice(i, i + maxChunk));
await sendHeader('DONE', (Date.now() / 1000) | 0);
await send(progress, 'DATA', content.slice(i, i + maxChunk));
await sendHeader(progress, 'DONE', (Date.now() / 1000) | 0);
const result = await progress.race(new Promise<Buffer>(f => socket.once('data', f)));
const code = result.slice(0, 4).toString();
if (code !== 'OKAY')
Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/src/server/bidi/bidiPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,11 @@ export class BidiPage implements PageDelegate {

async setInputFilePaths(progress: Progress, handle: dom.ElementHandle<HTMLInputElement>, paths: string[]): Promise<void> {
const fromContext = toBidiExecutionContext(handle._context);
await this._session.send('input.setFiles', {
await progress.race(this._session.send('input.setFiles', {
context: this._session.sessionId,
element: await fromContext.nodeIdForElementHandle(handle),
element: await progress.race(fromContext.nodeIdForElementHandle(handle)),
files: paths,
});
}));
}

async adoptElementHandle<T extends Node>(handle: dom.ElementHandle<T>, to: dom.FrameExecutionContext): Promise<dom.ElementHandle<T>> {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export abstract class Browser extends SdkObject {
}

async killForTests(progress: Progress) {
await this.options.browserProcess.kill();
await progress.race(this.options.browserProcess.kill());
}
}

Expand Down
18 changes: 9 additions & 9 deletions packages/playwright-core/src/server/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export abstract class BrowserContext<EM extends EventMap = EventMap> extends Sdk
if (!this.possiblyUninitializedPages().length) {
const waitForEvent = helper.waitForEvent(progress, this, BrowserContext.Events.Page);
// Race against BrowserContext.close
await Promise.race([waitForEvent.promise, this._closePromise]);
await progress.race(Promise.race([waitForEvent.promise, this._closePromise]));
}
const page = this.possiblyUninitializedPages()[0];
if (!page)
Expand Down Expand Up @@ -509,7 +509,7 @@ export abstract class BrowserContext<EM extends EventMap = EventMap> extends Sdk
async addRequestInterceptor(progress: Progress, handler: network.RouteHandler): Promise<void> {
// Note: progress is intentionally ignored, because this operation is not cancellable and should not block in the browser anyway.
this.requestInterceptors.push(handler);
await this.doUpdateRequestInterception();
await progress.race(this.doUpdateRequestInterception());
}

async removeRequestInterceptor(handler: network.RouteHandler): Promise<void> {
Expand Down Expand Up @@ -545,15 +545,15 @@ export abstract class BrowserContext<EM extends EventMap = EventMap> extends Sdk
this._closedStatus = 'closing';

for (const harRecorder of this._harRecorders.values())
await harRecorder.flush();
await this.tracing.flush();
await Promise.all(this.pages().map(page => page.screencast.handlePageOrContextClose()));
await progress.race(harRecorder.flush());
await progress.race(this.tracing.flush());
await progress.race(Promise.all(this.pages().map(page => page.screencast.handlePageOrContextClose())));

if (this._customCloseHandler) {
await this._customCloseHandler();
await progress.race(this._customCloseHandler());
} else {
// Close the context.
const disposition = await this.doClose(options.reason);
const disposition = await progress.race(this.doClose(options.reason));
if (disposition === 'close-browser')
await this._browser.close(progress, { reason: options.reason });
}
Expand All @@ -563,7 +563,7 @@ export abstract class BrowserContext<EM extends EventMap = EventMap> extends Sdk
const promises: Promise<void>[] = [];
promises.push(this._deleteAllDownloads());
promises.push(this._deleteAllTempDirs());
await Promise.all(promises);
await progress.race(Promise.all(promises));

// Custom handler should trigger didCloseInternal itself.
if (!this._customCloseHandler)
Expand Down Expand Up @@ -616,7 +616,7 @@ export abstract class BrowserContext<EM extends EventMap = EventMap> extends Sdk
if (!origin || !originsToSave.has(origin))
continue;
try {
const storage: SerializedStorage = await page.mainFrame().nonStallingEvaluateInExistingContext(collectScript, 'utility');
const storage: SerializedStorage = await progress.race(page.mainFrame().nonStallingEvaluateInExistingContext(collectScript, 'utility'));
if (storage.localStorage.length || storage.indexedDB?.length)
result.origins.push({ origin, localStorage: storage.localStorage, indexedDB: storage.indexedDB });
originsToSave.delete(origin);
Expand Down
8 changes: 4 additions & 4 deletions packages/playwright-core/src/server/browserType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export abstract class BrowserType extends SdkObject {
await browser._defaultContext!.loadDefaultContext(progress);
return browser;
} catch (error) {
await browserProcess.close().catch(() => {});
await progress.race(browserProcess.close().catch(() => {}));
throw error;
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ export abstract class BrowserType extends SdkObject {
let transport: ConnectionTransport | undefined = undefined;
let browserProcess: BrowserProcess | undefined = undefined;
const exitPromise = new ManualPromise();
const { launchedProcess, gracefullyClose, kill } = await launchProcess({
const { launchedProcess, gracefullyClose, kill } = await progress.race(launchProcess({
command: prepared.executable,
args: prepared.browserArguments,
env: this.amendEnvironment(env, prepared.userDataDir, isPersistent, options),
Expand Down Expand Up @@ -241,7 +241,7 @@ export abstract class BrowserType extends SdkObject {
if (browserProcess && browserProcess.onclose)
browserProcess.onclose(exitCode, signal);
},
});
}));

async function closeOrKill(timeout: number): Promise<void> {
let timer: NodeJS.Timeout;
Expand Down Expand Up @@ -280,7 +280,7 @@ export abstract class BrowserType extends SdkObject {
}
return { browserProcess, artifactsDir: prepared.artifactsDir, userDataDir: prepared.userDataDir, transport };
} catch (error) {
await closeOrKill(DEFAULT_PLAYWRIGHT_TIMEOUT).catch(() => {});
await progress.race(closeOrKill(DEFAULT_PLAYWRIGHT_TIMEOUT).catch(() => {}));
throw error;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/server/chromium/chromium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class Chromium extends BrowserType {
browser.on(Browser.Events.Disconnected, doCleanup);
return browser;
} catch (error) {
await doClose().catch(() => {});
await progress.race(doClose().catch(() => {}));
throw error;
}
}
Expand Down Expand Up @@ -289,7 +289,7 @@ export class Chromium extends BrowserType {
headers: headersObjectToArray(headers),
}, disconnectFromSelenium);
} catch (e) {
await disconnectFromSelenium();
await progress.race(disconnectFromSelenium());
throw e;
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/playwright-core/src/server/chromium/crDragDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ export class DragManager {
let expectingDrag = false;
await progress.race(this._crPage._page.safeNonStallingEvaluateInAllFrames(`(${setupDragListeners.toString()})()`, 'utility'));
client.on('Input.dragIntercepted', onDragIntercepted!);
await client.send('Input.setInterceptDrags', { enabled: true });
await progress.race(client.send('Input.setInterceptDrags', { enabled: true }));
try {
await progress.race(moveCallback());
expectingDrag = (await Promise.all(this._crPage._page.frames().map(async frame => {
expectingDrag = (await progress.race(Promise.all(this._crPage._page.frames().map(async frame => {
return frame.nonStallingEvaluateInExistingContext('window.__cleanupDrag?.()', 'utility').catch(() => false);
}))).some(x => x);
})))).some(x => x);
} finally {
client.off('Input.dragIntercepted', onDragIntercepted!);
await client.send('Input.setInterceptDrags', { enabled: false });
await progress.race(client.send('Input.setInterceptDrags', { enabled: false }));
}
this._dragState = expectingDrag ? (await dragInterceptedPromise).data : null;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/chromium/crInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class RawMouseImpl implements input.RawMouse {
if (forClick) {
// Avoid extra protocol calls related to drag and drop, because click relies on
// move-down-up protocol commands being sent synchronously.
await actualMove();
await progress.race(actualMove());
return;
}
await this._dragManager.interceptDragCausedByMove(progress, x, y, button, buttons, modifiers, actualMove);
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/server/chromium/crPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ export class CRPage implements PageDelegate {
if (!frame)
throw new Error('Cannot set input files to detached input element');
const parentSession = this._sessionForFrame(frame);
await parentSession._client.send('DOM.setFileInputFiles', {
await progress.race(parentSession._client.send('DOM.setFileInputFiles', {
objectId: handle._objectId,
files
});
}));
}

async adoptElementHandle<T extends Node>(handle: dom.ElementHandle<T>, to: dom.FrameExecutionContext): Promise<dom.ElementHandle<T>> {
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/server/clock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export class Clock {
}

async resume(progress: Progress) {
await this._installIfNeeded();
await progress.race(this._installIfNeeded());
this._initScripts.push(await this._browserContext.addInitScript(nullProgress, `globalThis.__pwClock.controller.log('resume', ${Date.now()})`));
await this._evaluateInFrames(`globalThis.__pwClock.controller.resume()`);
await progress.race(this._evaluateInFrames(`globalThis.__pwClock.controller.resume()`));
}

async setFixedTime(time: string | number) {
Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/src/server/debugController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class DebugController extends SdkObject {
promises.push(recorder.hideHighlightedSelector());
promises.push(recorder.setMode('none'));
}
await Promise.all(promises);
await progress.race(Promise.all(promises));
return;
}

Expand Down Expand Up @@ -125,7 +125,7 @@ export class DebugController extends SdkObject {
else if (params.selector)
promises.push(recorder.setHighlightedSelector(params.selector));
}
await Promise.all(promises);
await progress.race(Promise.all(promises));
}

async hideHighlight(progress: Progress) {
Expand All @@ -135,7 +135,7 @@ export class DebugController extends SdkObject {
promises.push(recorder.hideHighlightedSelector());
// Hide all locator.highlight highlights.
promises.push(...this._playwright.allPages().map(p => p.hideHighlight().catch(() => {})));
await Promise.all(promises);
await progress.race(Promise.all(promises));
}

async resume(progress: Progress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class AndroidDeviceDispatcher extends Dispatcher<AndroidDevice, channels.
throw new Error('No mapping for ' + text[i] + ' found');
keyCodes.push(code);
}
await Promise.all(keyCodes.map(keyCode => this._object.send(progress, 'inputPress', { keyCode })));
await progress.race(Promise.all(keyCodes.map(keyCode => this._object.send(progress, 'inputPress', { keyCode }))));
}

async inputPress(params: channels.AndroidDeviceInputPressParams, progress: Progress) {
Expand Down
Loading
Loading