mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
chore: remove dedicated console channel (#27234)
This commit is contained in:
parent
4bf5af6d86
commit
287d720b8e
@ -96,8 +96,8 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
|
||||
this._serviceWorkers.add(serviceWorker);
|
||||
this.emit(Events.BrowserContext.ServiceWorker, serviceWorker);
|
||||
});
|
||||
this._channel.on('console', ({ message }) => {
|
||||
const consoleMessage = ConsoleMessage.from(message);
|
||||
this._channel.on('console', event => {
|
||||
const consoleMessage = new ConsoleMessage(event);
|
||||
this.emit(Events.BrowserContext.Console, consoleMessage);
|
||||
const page = consoleMessage.page();
|
||||
if (page)
|
||||
|
@ -24,7 +24,6 @@ import { JSHandle } from './jsHandle';
|
||||
import { Request, Response, Route, WebSocket } from './network';
|
||||
import { Page, BindingCall } from './page';
|
||||
import { Worker } from './worker';
|
||||
import { ConsoleMessage } from './consoleMessage';
|
||||
import { Dialog } from './dialog';
|
||||
import { parseError } from '../protocol/serializers';
|
||||
import { CDPSession } from './cdpSession';
|
||||
@ -240,9 +239,6 @@ export class Connection extends EventEmitter {
|
||||
case 'CDPSession':
|
||||
result = new CDPSession(parent, type, guid, initializer);
|
||||
break;
|
||||
case 'ConsoleMessage':
|
||||
result = new ConsoleMessage(parent, type, guid, initializer);
|
||||
break;
|
||||
case 'Dialog':
|
||||
result = new Dialog(parent, type, guid, initializer);
|
||||
break;
|
||||
|
@ -17,25 +17,19 @@
|
||||
import * as util from 'util';
|
||||
import { JSHandle } from './jsHandle';
|
||||
import type * as channels from '@protocol/channels';
|
||||
import { ChannelOwner } from './channelOwner';
|
||||
import type * as api from '../../types/types';
|
||||
import { Page } from './page';
|
||||
|
||||
type ConsoleMessageLocation = channels.ConsoleMessageInitializer['location'];
|
||||
type ConsoleMessageLocation = channels.BrowserContextConsoleEvent['location'];
|
||||
|
||||
export class ConsoleMessage extends ChannelOwner<channels.ConsoleMessageChannel> implements api.ConsoleMessage {
|
||||
static from(message: channels.ConsoleMessageChannel): ConsoleMessage {
|
||||
return (message as any)._object;
|
||||
}
|
||||
export class ConsoleMessage implements api.ConsoleMessage {
|
||||
|
||||
private _page: Page | null;
|
||||
private _event: channels.BrowserContextConsoleEvent;
|
||||
|
||||
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.ConsoleMessageInitializer) {
|
||||
super(parent, type, guid, initializer);
|
||||
// Note: currently, we only report console messages for pages and they always have a page.
|
||||
// However, in the future we might report console messages for service workers or something else,
|
||||
// where page() would be null.
|
||||
this._page = Page.fromNullable(initializer.page);
|
||||
constructor(event: channels.BrowserContextConsoleEvent) {
|
||||
this._page = event.page ? Page.from(event.page) : null;
|
||||
this._event = event;
|
||||
}
|
||||
|
||||
page() {
|
||||
@ -43,19 +37,19 @@ export class ConsoleMessage extends ChannelOwner<channels.ConsoleMessageChannel>
|
||||
}
|
||||
|
||||
type(): string {
|
||||
return this._initializer.type;
|
||||
return this._event.type;
|
||||
}
|
||||
|
||||
text(): string {
|
||||
return this._initializer.text;
|
||||
return this._event.text;
|
||||
}
|
||||
|
||||
args(): JSHandle[] {
|
||||
return this._initializer.args.map(JSHandle.from);
|
||||
return this._event.args.map(JSHandle.from);
|
||||
}
|
||||
|
||||
location(): ConsoleMessageLocation {
|
||||
return this._initializer.location;
|
||||
return this._event.location;
|
||||
}
|
||||
|
||||
[util.inspect.custom]() {
|
||||
|
@ -761,7 +761,15 @@ scheme.BrowserContextBindingCallEvent = tObject({
|
||||
binding: tChannel(['BindingCall']),
|
||||
});
|
||||
scheme.BrowserContextConsoleEvent = tObject({
|
||||
message: tChannel(['ConsoleMessage']),
|
||||
page: tChannel(['Page']),
|
||||
type: tString,
|
||||
text: tString,
|
||||
args: tArray(tChannel(['ElementHandle', 'JSHandle'])),
|
||||
location: tObject({
|
||||
url: tString,
|
||||
lineNumber: tNumber,
|
||||
columnNumber: tNumber,
|
||||
}),
|
||||
});
|
||||
scheme.BrowserContextCloseEvent = tOptional(tObject({}));
|
||||
scheme.BrowserContextDialogEvent = tObject({
|
||||
@ -2088,17 +2096,6 @@ scheme.WebSocketSocketErrorEvent = tObject({
|
||||
error: tString,
|
||||
});
|
||||
scheme.WebSocketCloseEvent = tOptional(tObject({}));
|
||||
scheme.ConsoleMessageInitializer = tObject({
|
||||
page: tChannel(['Page']),
|
||||
type: tString,
|
||||
text: tString,
|
||||
args: tArray(tChannel(['ElementHandle', 'JSHandle'])),
|
||||
location: tObject({
|
||||
url: tString,
|
||||
lineNumber: tNumber,
|
||||
columnNumber: tNumber,
|
||||
}),
|
||||
});
|
||||
scheme.BindingCallInitializer = tObject({
|
||||
frame: tChannel(['Frame']),
|
||||
name: tString,
|
||||
|
@ -33,12 +33,12 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { createGuid, urlMatches } from '../../utils';
|
||||
import { WritableStreamDispatcher } from './writableStreamDispatcher';
|
||||
import { ConsoleMessageDispatcher } from './consoleMessageDispatcher';
|
||||
import { DialogDispatcher } from './dialogDispatcher';
|
||||
import type { Page } from '../page';
|
||||
import type { Dialog } from '../dialog';
|
||||
import type { ConsoleMessage } from '../console';
|
||||
import { serializeError } from '../../protocol/serializers';
|
||||
import { ElementHandleDispatcher } from './elementHandlerDispatcher';
|
||||
|
||||
export class BrowserContextDispatcher extends Dispatcher<BrowserContext, channels.BrowserContextChannel, DispatcherScope> implements channels.BrowserContextChannel {
|
||||
_type_EventTarget = true;
|
||||
@ -89,8 +89,16 @@ export class BrowserContextDispatcher extends Dispatcher<BrowserContext, channel
|
||||
this._dispatchEvent('pageError', { error: serializeError(error), page: PageDispatcher.from(this, page) });
|
||||
});
|
||||
this.addObjectListener(BrowserContext.Events.Console, (message: ConsoleMessage) => {
|
||||
if (this._shouldDispatchEvent(message.page(), 'console'))
|
||||
this._dispatchEvent('console', { message: new ConsoleMessageDispatcher(PageDispatcher.from(this, message.page()), message) });
|
||||
if (this._shouldDispatchEvent(message.page(), 'console')) {
|
||||
const pageDispatcher = PageDispatcher.from(this, message.page());
|
||||
this._dispatchEvent('console', {
|
||||
page: pageDispatcher,
|
||||
type: message.type(),
|
||||
text: message.text(),
|
||||
args: message.args().map(a => ElementHandleDispatcher.fromJSHandle(pageDispatcher, a)),
|
||||
location: message.location(),
|
||||
});
|
||||
}
|
||||
});
|
||||
this.addObjectListener(BrowserContext.Events.Dialog, (dialog: Dialog) => {
|
||||
if (this._shouldDispatchEvent(dialog.page(), 'dialog'))
|
||||
|
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the 'License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { ConsoleMessage } from '../console';
|
||||
import type * as channels from '@protocol/channels';
|
||||
import type { PageDispatcher } from './pageDispatcher';
|
||||
import { Dispatcher } from './dispatcher';
|
||||
import { ElementHandleDispatcher } from './elementHandlerDispatcher';
|
||||
|
||||
export class ConsoleMessageDispatcher extends Dispatcher<ConsoleMessage, channels.ConsoleMessageChannel, PageDispatcher> implements channels.ConsoleMessageChannel {
|
||||
_type_ConsoleMessage = true;
|
||||
|
||||
constructor(page: PageDispatcher, message: ConsoleMessage) {
|
||||
super(page, message, 'ConsoleMessage', {
|
||||
type: message.type(),
|
||||
text: message.text(),
|
||||
args: message.args().map(a => ElementHandleDispatcher.fromJSHandle(page, a)),
|
||||
location: message.location(),
|
||||
page,
|
||||
});
|
||||
}
|
||||
}
|
@ -38,7 +38,6 @@ export type InitializerTraits<T> =
|
||||
T extends TracingChannel ? TracingInitializer :
|
||||
T extends DialogChannel ? DialogInitializer :
|
||||
T extends BindingCallChannel ? BindingCallInitializer :
|
||||
T extends ConsoleMessageChannel ? ConsoleMessageInitializer :
|
||||
T extends WebSocketChannel ? WebSocketInitializer :
|
||||
T extends ResponseChannel ? ResponseInitializer :
|
||||
T extends RouteChannel ? RouteInitializer :
|
||||
@ -76,7 +75,6 @@ export type EventsTraits<T> =
|
||||
T extends TracingChannel ? TracingEvents :
|
||||
T extends DialogChannel ? DialogEvents :
|
||||
T extends BindingCallChannel ? BindingCallEvents :
|
||||
T extends ConsoleMessageChannel ? ConsoleMessageEvents :
|
||||
T extends WebSocketChannel ? WebSocketEvents :
|
||||
T extends ResponseChannel ? ResponseEvents :
|
||||
T extends RouteChannel ? RouteEvents :
|
||||
@ -114,7 +112,6 @@ export type EventTargetTraits<T> =
|
||||
T extends TracingChannel ? TracingEventTarget :
|
||||
T extends DialogChannel ? DialogEventTarget :
|
||||
T extends BindingCallChannel ? BindingCallEventTarget :
|
||||
T extends ConsoleMessageChannel ? ConsoleMessageEventTarget :
|
||||
T extends WebSocketChannel ? WebSocketEventTarget :
|
||||
T extends ResponseChannel ? ResponseEventTarget :
|
||||
T extends RouteChannel ? RouteEventTarget :
|
||||
@ -1445,7 +1442,15 @@ export type BrowserContextBindingCallEvent = {
|
||||
binding: BindingCallChannel,
|
||||
};
|
||||
export type BrowserContextConsoleEvent = {
|
||||
message: ConsoleMessageChannel,
|
||||
page: PageChannel,
|
||||
type: string,
|
||||
text: string,
|
||||
args: JSHandleChannel[],
|
||||
location: {
|
||||
url: string,
|
||||
lineNumber: number,
|
||||
columnNumber: number,
|
||||
},
|
||||
};
|
||||
export type BrowserContextCloseEvent = {};
|
||||
export type BrowserContextDialogEvent = {
|
||||
@ -3707,27 +3712,6 @@ export interface WebSocketEvents {
|
||||
'close': WebSocketCloseEvent;
|
||||
}
|
||||
|
||||
// ----------- ConsoleMessage -----------
|
||||
export type ConsoleMessageInitializer = {
|
||||
page: PageChannel,
|
||||
type: string,
|
||||
text: string,
|
||||
args: JSHandleChannel[],
|
||||
location: {
|
||||
url: string,
|
||||
lineNumber: number,
|
||||
columnNumber: number,
|
||||
},
|
||||
};
|
||||
export interface ConsoleMessageEventTarget {
|
||||
}
|
||||
export interface ConsoleMessageChannel extends ConsoleMessageEventTarget, Channel {
|
||||
_type_ConsoleMessage: boolean;
|
||||
}
|
||||
|
||||
export interface ConsoleMessageEvents {
|
||||
}
|
||||
|
||||
// ----------- BindingCall -----------
|
||||
export type BindingCallInitializer = {
|
||||
frame: FrameChannel,
|
||||
|
@ -1176,7 +1176,18 @@ BrowserContext:
|
||||
|
||||
console:
|
||||
parameters:
|
||||
message: ConsoleMessage
|
||||
page: Page
|
||||
type: string
|
||||
text: string
|
||||
args:
|
||||
type: array
|
||||
items: JSHandle
|
||||
location:
|
||||
type: object
|
||||
properties:
|
||||
url: string
|
||||
lineNumber: number
|
||||
columnNumber: number
|
||||
|
||||
close:
|
||||
|
||||
@ -2944,25 +2955,6 @@ WebSocket:
|
||||
close:
|
||||
|
||||
|
||||
ConsoleMessage:
|
||||
type: interface
|
||||
|
||||
initializer:
|
||||
page: Page
|
||||
type: string
|
||||
text: string
|
||||
args:
|
||||
type: array
|
||||
items: JSHandle
|
||||
location:
|
||||
type: object
|
||||
properties:
|
||||
url: string
|
||||
lineNumber: number
|
||||
columnNumber: number
|
||||
|
||||
|
||||
|
||||
BindingCall:
|
||||
type: interface
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user