mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix!: make console warn level compatible with WebDriver BiDi (#11790)
This commit is contained in:
parent
f18d44761c
commit
d4e9d8d591
@ -14,7 +14,7 @@ export type ConsoleMessageType =
|
|||||||
| 'debug'
|
| 'debug'
|
||||||
| 'info'
|
| 'info'
|
||||||
| 'error'
|
| 'error'
|
||||||
| 'warning'
|
| 'warn'
|
||||||
| 'dir'
|
| 'dir'
|
||||||
| 'dirxml'
|
| 'dirxml'
|
||||||
| 'table'
|
| 'table'
|
||||||
|
@ -33,6 +33,7 @@ import {Coverage} from '../cdp/Coverage.js';
|
|||||||
import {EmulationManager as CdpEmulationManager} from '../cdp/EmulationManager.js';
|
import {EmulationManager as CdpEmulationManager} from '../cdp/EmulationManager.js';
|
||||||
import {FrameTree} from '../cdp/FrameTree.js';
|
import {FrameTree} from '../cdp/FrameTree.js';
|
||||||
import {Tracing} from '../cdp/Tracing.js';
|
import {Tracing} from '../cdp/Tracing.js';
|
||||||
|
import type {ConsoleMessageType} from '../common/ConsoleMessage.js';
|
||||||
import {
|
import {
|
||||||
ConsoleMessage,
|
ConsoleMessage,
|
||||||
type ConsoleMessageLocation,
|
type ConsoleMessageLocation,
|
||||||
@ -408,7 +409,7 @@ export class BidiPage extends Page {
|
|||||||
this.emit(
|
this.emit(
|
||||||
PageEvent.Console,
|
PageEvent.Console,
|
||||||
new ConsoleMessage(
|
new ConsoleMessage(
|
||||||
event.method as any,
|
event.method as ConsoleMessageType,
|
||||||
text,
|
text,
|
||||||
args,
|
args,
|
||||||
getStackTraceLocations(event.stackTrace)
|
getStackTraceLocations(event.stackTrace)
|
||||||
|
@ -85,6 +85,15 @@ import {
|
|||||||
} from './utils.js';
|
} from './utils.js';
|
||||||
import {CdpWebWorker} from './WebWorker.js';
|
import {CdpWebWorker} from './WebWorker.js';
|
||||||
|
|
||||||
|
function convertConsoleMessageLevel(method: string): ConsoleMessageType {
|
||||||
|
switch (method) {
|
||||||
|
case 'warning':
|
||||||
|
return 'warn';
|
||||||
|
default:
|
||||||
|
return method as ConsoleMessageType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -475,7 +484,12 @@ export class CdpPage extends Page {
|
|||||||
if (source !== 'worker') {
|
if (source !== 'worker') {
|
||||||
this.emit(
|
this.emit(
|
||||||
PageEvent.Console,
|
PageEvent.Console,
|
||||||
new ConsoleMessage(level, text, [], [{url, lineNumber}])
|
new ConsoleMessage(
|
||||||
|
convertConsoleMessageLevel(level),
|
||||||
|
text,
|
||||||
|
[],
|
||||||
|
[{url, lineNumber}]
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -811,7 +825,11 @@ export class CdpPage extends Page {
|
|||||||
const values = event.args.map(arg => {
|
const values = event.args.map(arg => {
|
||||||
return createCdpHandle(context._world, arg);
|
return createCdpHandle(context._world, arg);
|
||||||
});
|
});
|
||||||
this.#addConsoleMessage(event.type, values, event.stackTrace);
|
this.#addConsoleMessage(
|
||||||
|
convertConsoleMessageLevel(event.type),
|
||||||
|
values,
|
||||||
|
event.stackTrace
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async #onBindingCalled(
|
async #onBindingCalled(
|
||||||
@ -843,7 +861,7 @@ export class CdpPage extends Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#addConsoleMessage(
|
#addConsoleMessage(
|
||||||
eventType: ConsoleMessageType,
|
eventType: string,
|
||||||
args: JSHandle[],
|
args: JSHandle[],
|
||||||
stackTrace?: Protocol.Runtime.StackTrace
|
stackTrace?: Protocol.Runtime.StackTrace
|
||||||
): void {
|
): void {
|
||||||
@ -875,7 +893,7 @@ export class CdpPage extends Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const message = new ConsoleMessage(
|
const message = new ConsoleMessage(
|
||||||
eventType,
|
convertConsoleMessageLevel(eventType),
|
||||||
textTokens.join(' '),
|
textTokens.join(' '),
|
||||||
args,
|
args,
|
||||||
stackTraceLocations
|
stackTraceLocations
|
||||||
|
@ -8,7 +8,6 @@ import type {Protocol} from 'devtools-protocol';
|
|||||||
import type {CDPSession} from '../api/CDPSession.js';
|
import type {CDPSession} from '../api/CDPSession.js';
|
||||||
import type {Realm} from '../api/Realm.js';
|
import type {Realm} from '../api/Realm.js';
|
||||||
import {WebWorker} from '../api/WebWorker.js';
|
import {WebWorker} from '../api/WebWorker.js';
|
||||||
import type {ConsoleMessageType} from '../common/ConsoleMessage.js';
|
|
||||||
import {TimeoutSettings} from '../common/TimeoutSettings.js';
|
import {TimeoutSettings} from '../common/TimeoutSettings.js';
|
||||||
import {debugError} from '../common/util.js';
|
import {debugError} from '../common/util.js';
|
||||||
|
|
||||||
@ -20,7 +19,7 @@ import {CdpJSHandle} from './JSHandle.js';
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export type ConsoleAPICalledCallback = (
|
export type ConsoleAPICalledCallback = (
|
||||||
eventType: ConsoleMessageType,
|
eventType: string,
|
||||||
handles: CdpJSHandle[],
|
handles: CdpJSHandle[],
|
||||||
trace?: Protocol.Runtime.StackTrace
|
trace?: Protocol.Runtime.StackTrace
|
||||||
) => void;
|
) => void;
|
||||||
|
@ -35,7 +35,7 @@ export type ConsoleMessageType =
|
|||||||
| 'debug'
|
| 'debug'
|
||||||
| 'info'
|
| 'info'
|
||||||
| 'error'
|
| 'error'
|
||||||
| 'warning'
|
| 'warn'
|
||||||
| 'dir'
|
| 'dir'
|
||||||
| 'dirxml'
|
| 'dirxml'
|
||||||
| 'table'
|
| 'table'
|
||||||
|
@ -922,7 +922,7 @@
|
|||||||
"testIdPattern": "[page.spec] Page Page.Events.Console should work for different console API calls with logging functions",
|
"testIdPattern": "[page.spec] Page Page.Events.Console should work for different console API calls with logging functions",
|
||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["webDriverBiDi"],
|
"parameters": ["webDriverBiDi"],
|
||||||
"expectations": ["FAIL"]
|
"expectations": ["PASS"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"testIdPattern": "[page.spec] Page Page.Events.error should throw when page crashes",
|
"testIdPattern": "[page.spec] Page Page.Events.error should throw when page crashes",
|
||||||
|
@ -445,7 +445,7 @@ describe('Page', function () {
|
|||||||
messages.map(msg => {
|
messages.map(msg => {
|
||||||
return msg.type();
|
return msg.type();
|
||||||
})
|
})
|
||||||
).toEqual(['trace', 'dir', 'warning', 'error', 'log']);
|
).toEqual(['trace', 'dir', 'warn', 'error', 'log']);
|
||||||
expect(
|
expect(
|
||||||
messages.map(msg => {
|
messages.map(msg => {
|
||||||
return msg.text();
|
return msg.text();
|
||||||
|
Loading…
Reference in New Issue
Block a user