chore: JavaScript error should produce pageerror
events (#9884)
This commit is contained in:
parent
a5149d52f5
commit
3ea15dc395
@ -25,6 +25,7 @@ import {
|
|||||||
import {ConsoleMessage, ConsoleMessageLocation} from '../ConsoleMessage.js';
|
import {ConsoleMessage, ConsoleMessageLocation} from '../ConsoleMessage.js';
|
||||||
import {Handler} from '../EventEmitter.js';
|
import {Handler} from '../EventEmitter.js';
|
||||||
import {EvaluateFunc, HandleFor} from '../types.js';
|
import {EvaluateFunc, HandleFor} from '../types.js';
|
||||||
|
import {debugError} from '../util.js';
|
||||||
|
|
||||||
import {Context, getBidiHandle} from './Context.js';
|
import {Context, getBidiHandle} from './Context.js';
|
||||||
import {BidiSerializer} from './Serializer.js';
|
import {BidiSerializer} from './Serializer.js';
|
||||||
@ -81,14 +82,28 @@ export class Page extends PageBase {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else if (isJavaScriptLogEntry(event)) {
|
} else if (isJavaScriptLogEntry(event)) {
|
||||||
this.emit(
|
let message = event.text ?? '';
|
||||||
PageEmittedEvents.Console,
|
|
||||||
new ConsoleMessage(
|
if (event.stackTrace) {
|
||||||
event.level as any,
|
for (const callFrame of event.stackTrace.callFrames) {
|
||||||
event.text ?? '',
|
const location =
|
||||||
[],
|
callFrame.url +
|
||||||
getStackTraceLocations(event.stackTrace)
|
':' +
|
||||||
)
|
callFrame.lineNumber +
|
||||||
|
':' +
|
||||||
|
callFrame.columnNumber;
|
||||||
|
const functionName = callFrame.functionName || '<anonymous>';
|
||||||
|
message += `\n at ${functionName} (${location})`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const error = new Error(message);
|
||||||
|
error.stack = ''; // Don't capture Puppeteer stacktrace.
|
||||||
|
|
||||||
|
this.emit(PageEmittedEvents.PageError, error);
|
||||||
|
} else {
|
||||||
|
debugError(
|
||||||
|
`Unhandled LogEntry with type "${event.type}", text "${event.text}" and level "${event.level}"`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,7 +206,9 @@ function isJavaScriptLogEntry(
|
|||||||
return event.type === 'javascript';
|
return event.type === 'javascript';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStackTraceLocations(stackTrace?: Bidi.Script.StackTrace) {
|
function getStackTraceLocations(
|
||||||
|
stackTrace?: Bidi.Script.StackTrace
|
||||||
|
): ConsoleMessageLocation[] {
|
||||||
const stackTraceLocations: ConsoleMessageLocation[] = [];
|
const stackTraceLocations: ConsoleMessageLocation[] = [];
|
||||||
if (stackTrace) {
|
if (stackTrace) {
|
||||||
for (const callFrame of stackTrace.callFrames) {
|
for (const callFrame of stackTrace.callFrames) {
|
||||||
|
@ -2050,5 +2050,11 @@
|
|||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["chrome", "webDriverBiDi"],
|
"parameters": ["chrome", "webDriverBiDi"],
|
||||||
"expectations": ["FAIL"]
|
"expectations": ["FAIL"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"testIdPattern": "[page.spec] Page Page.Events.PageError *",
|
||||||
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
|
"parameters": ["webDriverBiDi"],
|
||||||
|
"expectations": ["PASS"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user