diff --git a/client/lib/CoreSession.ts b/client/lib/CoreSession.ts index 4c609c0f5..25c9ae086 100644 --- a/client/lib/CoreSession.ts +++ b/client/lib/CoreSession.ts @@ -204,6 +204,10 @@ export default class CoreSession implements IJsPathEventTarget { } } + public async pause(): Promise { + await this.commandQueue.run('Session.pauseCommands'); + } + private async doClose(force: boolean): Promise<{ didKeepAlive: boolean; message: string }> { await this.commandQueue.flush(); for (const tab of this.tabsById.values()) { diff --git a/client/lib/Hero.ts b/client/lib/Hero.ts index e53804a0a..2c2fc16eb 100644 --- a/client/lib/Hero.ts +++ b/client/lib/Hero.ts @@ -420,6 +420,11 @@ export default class Hero extends AwaitedEventTarget<{ return await this.getComputedVisibility(element as any).then(x => x.isVisible); } + public async pause(): Promise { + const session = await this.#getCoreSessionOrReject(); + await session.pause(); + } + public querySelector(selector: string): ISuperNode { return this.activeTab.querySelector(selector); } diff --git a/core/lib/Commands.ts b/core/lib/Commands.ts index 41e2e77a3..b3752b01a 100644 --- a/core/lib/Commands.ts +++ b/core/lib/Commands.ts @@ -11,6 +11,8 @@ import { TypedEventEmitter } from '@ulixee/commons/lib/eventUtils'; export default class Commands extends TypedEventEmitter<{ start: ICommandMeta; finish: ICommandMeta; + pause: void; + resume: void; }> { public readonly history: ICommandMeta[] = []; public get last(): ICommandMeta | undefined { @@ -54,11 +56,13 @@ export default class Commands extends TypedEventEmitter<{ if (!this.commandLockPromise || this.commandLockPromise.isResolved) { this.commandLockPromise = new Resolvable(); } + this.emit('pause'); } public resume(): void { this.commandLockPromise.resolve(); this.commandLockPromise = null; + this.emit('resume'); } public create(