Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture and log page errors #374

Merged
merged 8 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export type NetworkInfo = {
export type BrowserMessage = {
text: string;
type: string;
stacktrace?: string;
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
} & DefaultPluginOutput;

export type PluginOutput = {
Expand Down
19 changes: 19 additions & 0 deletions src/plugins/browser-console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,31 @@ export class BrowserConsole {
}
};

private pageErrorEventListener = (error: Error) => {
if (!this._currentStep) {
return;
}
const { name, index } = this._currentStep;
this.messages.push({
timestamp: getTimestamp(),
text: error.message,
type: 'error',
step: { name, index },
stacktrace: error.stack.toString(),
vigneshshanmugam marked this conversation as resolved.
Show resolved Hide resolved
});
if (this.messages.length > defaultMessageLimit) {
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
this.messages.splice(0, 1);
}
};

start() {
this.driver.page.on('console', this.consoleEventListener);
this.driver.page.on('pageerror', this.pageErrorEventListener);
}

stop() {
this.driver.page.off('console', this.consoleEventListener);
this.driver.page.off('pageerror', this.pageErrorEventListener);
return this.messages;
}
}