fix: update terminal size dynamically (#5250)
This commit is contained in:
parent
d96c547389
commit
8a8d8ea370
|
|
@ -66,11 +66,21 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel,
|
||||||
this._channel.on('route', ({ route, request }) => this._onRoute(network.Route.from(route), network.Request.from(request)));
|
this._channel.on('route', ({ route, request }) => this._onRoute(network.Route.from(route), network.Request.from(request)));
|
||||||
this._stdout = process.stdout;
|
this._stdout = process.stdout;
|
||||||
this._stderr = process.stderr;
|
this._stderr = process.stderr;
|
||||||
this._channel.on('stdout', ({ data }) => this._stdout.write(Buffer.from(data, 'base64')));
|
this._channel.on('stdout', ({ data }) => {
|
||||||
this._channel.on('stderr', ({ data }) => this._stderr.write(Buffer.from(data, 'base64')));
|
this._stdout.write(Buffer.from(data, 'base64'));
|
||||||
|
this._pushTerminalSize();
|
||||||
|
});
|
||||||
|
this._channel.on('stderr', ({ data }) => {
|
||||||
|
this._stderr.write(Buffer.from(data, 'base64'));
|
||||||
|
this._pushTerminalSize();
|
||||||
|
});
|
||||||
this._closedPromise = new Promise(f => this.once(Events.BrowserContext.Close, f));
|
this._closedPromise = new Promise(f => this.once(Events.BrowserContext.Close, f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _pushTerminalSize() {
|
||||||
|
this._channel.setTerminalSizeNoReply({ rows: process.stdout.rows, columns: process.stdout.columns }).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
private _onPage(page: Page): void {
|
private _onPage(page: Page): void {
|
||||||
this._pages.add(page);
|
this._pages.add(page);
|
||||||
this.emit(Events.BrowserContext.Page, page);
|
this.emit(Events.BrowserContext.Page, page);
|
||||||
|
|
@ -279,6 +289,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel,
|
||||||
terminal?: boolean,
|
terminal?: boolean,
|
||||||
outputFile?: string
|
outputFile?: string
|
||||||
}) {
|
}) {
|
||||||
|
this._pushTerminalSize();
|
||||||
await this._channel.recorderSupplementEnable(params);
|
await this._channel.recorderSupplementEnable(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -154,4 +154,8 @@ export class BrowserContextDispatcher extends Dispatcher<BrowserContext, channel
|
||||||
const crBrowserContext = this._object as CRBrowserContext;
|
const crBrowserContext = this._object as CRBrowserContext;
|
||||||
return { session: new CDPSessionDispatcher(this._scope, await crBrowserContext.newCDPSession((params.page as PageDispatcher)._object)) };
|
return { session: new CDPSessionDispatcher(this._scope, await crBrowserContext.newCDPSession((params.page as PageDispatcher)._object)) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setTerminalSizeNoReply(params: channels.BrowserContextSetTerminalSizeNoReplyParams): Promise<void> {
|
||||||
|
this._context.terminalSize = params;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -562,6 +562,7 @@ export interface BrowserContextChannel extends Channel {
|
||||||
pause(params?: BrowserContextPauseParams, metadata?: Metadata): Promise<BrowserContextPauseResult>;
|
pause(params?: BrowserContextPauseParams, metadata?: Metadata): Promise<BrowserContextPauseResult>;
|
||||||
recorderSupplementEnable(params: BrowserContextRecorderSupplementEnableParams, metadata?: Metadata): Promise<BrowserContextRecorderSupplementEnableResult>;
|
recorderSupplementEnable(params: BrowserContextRecorderSupplementEnableParams, metadata?: Metadata): Promise<BrowserContextRecorderSupplementEnableResult>;
|
||||||
crNewCDPSession(params: BrowserContextCrNewCDPSessionParams, metadata?: Metadata): Promise<BrowserContextCrNewCDPSessionResult>;
|
crNewCDPSession(params: BrowserContextCrNewCDPSessionParams, metadata?: Metadata): Promise<BrowserContextCrNewCDPSessionResult>;
|
||||||
|
setTerminalSizeNoReply(params: BrowserContextSetTerminalSizeNoReplyParams, metadata?: Metadata): Promise<BrowserContextSetTerminalSizeNoReplyResult>;
|
||||||
}
|
}
|
||||||
export type BrowserContextBindingCallEvent = {
|
export type BrowserContextBindingCallEvent = {
|
||||||
binding: BindingCallChannel,
|
binding: BindingCallChannel,
|
||||||
|
|
@ -741,6 +742,15 @@ export type BrowserContextCrNewCDPSessionOptions = {
|
||||||
export type BrowserContextCrNewCDPSessionResult = {
|
export type BrowserContextCrNewCDPSessionResult = {
|
||||||
session: CDPSessionChannel,
|
session: CDPSessionChannel,
|
||||||
};
|
};
|
||||||
|
export type BrowserContextSetTerminalSizeNoReplyParams = {
|
||||||
|
rows?: number,
|
||||||
|
columns?: number,
|
||||||
|
};
|
||||||
|
export type BrowserContextSetTerminalSizeNoReplyOptions = {
|
||||||
|
rows?: number,
|
||||||
|
columns?: number,
|
||||||
|
};
|
||||||
|
export type BrowserContextSetTerminalSizeNoReplyResult = void;
|
||||||
|
|
||||||
// ----------- Page -----------
|
// ----------- Page -----------
|
||||||
export type PageInitializer = {
|
export type PageInitializer = {
|
||||||
|
|
|
||||||
|
|
@ -624,6 +624,11 @@ BrowserContext:
|
||||||
returns:
|
returns:
|
||||||
session: CDPSession
|
session: CDPSession
|
||||||
|
|
||||||
|
setTerminalSizeNoReply:
|
||||||
|
parameters:
|
||||||
|
rows: number?
|
||||||
|
columns: number?
|
||||||
|
|
||||||
events:
|
events:
|
||||||
|
|
||||||
bindingCall:
|
bindingCall:
|
||||||
|
|
|
||||||
|
|
@ -351,6 +351,10 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
||||||
scheme.BrowserContextCrNewCDPSessionParams = tObject({
|
scheme.BrowserContextCrNewCDPSessionParams = tObject({
|
||||||
page: tChannel('Page'),
|
page: tChannel('Page'),
|
||||||
});
|
});
|
||||||
|
scheme.BrowserContextSetTerminalSizeNoReplyParams = tObject({
|
||||||
|
rows: tOptional(tNumber),
|
||||||
|
columns: tOptional(tNumber),
|
||||||
|
});
|
||||||
scheme.PageSetDefaultNavigationTimeoutNoReplyParams = tObject({
|
scheme.PageSetDefaultNavigationTimeoutNoReplyParams = tObject({
|
||||||
timeout: tNumber,
|
timeout: tNumber,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,7 @@ export abstract class BrowserContext extends EventEmitter {
|
||||||
private _selectors?: Selectors;
|
private _selectors?: Selectors;
|
||||||
readonly _actionListeners = new Set<ActionListener>();
|
readonly _actionListeners = new Set<ActionListener>();
|
||||||
private _origins = new Set<string>();
|
private _origins = new Set<string>();
|
||||||
|
terminalSize: { rows?: number, columns?: number } = {};
|
||||||
|
|
||||||
constructor(browser: Browser, options: types.BrowserContextOptions, browserContextId: string | undefined) {
|
constructor(browser: Browser, options: types.BrowserContextOptions, browserContextId: string | undefined) {
|
||||||
super();
|
super();
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ declare global {
|
||||||
playwrightRecorderSetUIState: (state: SetUIState) => Promise<void>;
|
playwrightRecorderSetUIState: (state: SetUIState) => Promise<void>;
|
||||||
playwrightRecorderResume: () => Promise<boolean>;
|
playwrightRecorderResume: () => Promise<boolean>;
|
||||||
playwrightRecorderShowRecorderPage: () => Promise<void>;
|
playwrightRecorderShowRecorderPage: () => Promise<void>;
|
||||||
|
playwrightRecorderPrintSelector: (text: string) => Promise<void>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -276,8 +277,10 @@ export class Recorder {
|
||||||
|
|
||||||
private _onClick(event: MouseEvent) {
|
private _onClick(event: MouseEvent) {
|
||||||
if (this._state.uiState.mode === 'inspecting' && !this._isInToolbar(event.target as HTMLElement)) {
|
if (this._state.uiState.mode === 'inspecting' && !this._isInToolbar(event.target as HTMLElement)) {
|
||||||
if (this._hoveredModel)
|
if (this._hoveredModel) {
|
||||||
copy(this._hoveredModel.selector);
|
copy(this._hoveredModel.selector);
|
||||||
|
window.playwrightRecorderPrintSelector(this._hoveredModel.selector);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this._shouldIgnoreMouseEvent(event))
|
if (this._shouldIgnoreMouseEvent(event))
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ export interface RecorderOutput {
|
||||||
|
|
||||||
export interface Writable {
|
export interface Writable {
|
||||||
write(data: string): void;
|
write(data: string): void;
|
||||||
|
columns(): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OutputMultiplexer implements RecorderOutput {
|
export class OutputMultiplexer implements RecorderOutput {
|
||||||
|
|
@ -156,7 +157,7 @@ export class TerminalOutput implements RecorderOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
popLn(text: string) {
|
popLn(text: string) {
|
||||||
const terminalWidth = process.stdout.columns || 80;
|
const terminalWidth = this._output.columns();
|
||||||
for (const line of text.split('\n')) {
|
for (const line of text.split('\n')) {
|
||||||
const terminalLines = ((line.length - 1) / terminalWidth | 0) + 1;
|
const terminalLines = ((line.length - 1) / terminalWidth | 0) + 1;
|
||||||
for (let i = 0; i < terminalLines; ++i)
|
for (let i = 0; i < terminalLines; ++i)
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,8 @@ export class RecorderSupplement {
|
||||||
highlighterType = 'python';
|
highlighterType = 'python';
|
||||||
|
|
||||||
const writable: Writable = {
|
const writable: Writable = {
|
||||||
write: (text: string) => context.emit(BrowserContext.Events.StdOut, text)
|
write: (text: string) => context.emit(BrowserContext.Events.StdOut, text),
|
||||||
|
columns: () => context.terminalSize.columns || 80
|
||||||
};
|
};
|
||||||
const outputs: RecorderOutput[] = [params.terminal ? new TerminalOutput(writable, highlighterType) : new FlushingTerminalOutput(writable)];
|
const outputs: RecorderOutput[] = [params.terminal ? new TerminalOutput(writable, highlighterType) : new FlushingTerminalOutput(writable)];
|
||||||
this._highlighterType = highlighterType;
|
this._highlighterType = highlighterType;
|
||||||
|
|
@ -142,7 +143,11 @@ export class RecorderSupplement {
|
||||||
}).catch(e => console.error(e));
|
}).catch(e => console.error(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
await this._context.exposeBinding('playwrightRecorderState', false, ({ page }) => {
|
await this._context.exposeBinding('playwrightRecorderPrintSelector', false, (_, text) => {
|
||||||
|
this._context.emit(BrowserContext.Events.StdOut, `Selector: \x1b[38;5;130m${text}\x1b[0m\n`);
|
||||||
|
});
|
||||||
|
|
||||||
|
await this._context.exposeBinding('playwrightRecorderState', false, () => {
|
||||||
const state: State = {
|
const state: State = {
|
||||||
uiState: this._recorderUIState,
|
uiState: this._recorderUIState,
|
||||||
canResume: this._app === 'pause',
|
canResume: this._app === 'pause',
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,10 @@
|
||||||
user-select: none;
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.source-line-number {
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
|
||||||
.source-line-highlighted {
|
.source-line-highlighted {
|
||||||
background-color: #ffc0cb7f;
|
background-color: #ffc0cb7f;
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue