Skip to content

Commit

Permalink
fix: log screenshot errors during debug mode (#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam authored Jul 29, 2024
1 parent 4fcf638 commit 41588ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions src/core/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,17 @@ export default class Runner {
}

async captureScreenshot(page: Driver['page'], step: Step) {
const buffer = await page
.screenshot({
try {
const buffer = await page.screenshot({
type: 'jpeg',
quality: 80,
timeout: 5000,
})
.catch(() => {});
/**
* Write the screenshot image buffer with additional details (step
* information) which could be extracted at the end of
* each journey without impacting the step timing information
*/
if (buffer) {
/**
* Write the screenshot image buffer with additional details (step
* information) which could be extracted at the end of
* each journey without impacting the step timing information
*/
const fileName = `${generateUniqueId()}.json`;
const screenshot: Screenshot = {
step,
Expand All @@ -126,6 +124,9 @@ export default class Runner {
JSON.stringify(screenshot)
);
log(`Runner: captured screenshot for (${step.name})`);
} catch (_) {
// Screenshot may fail sometimes, log and continue.
log(`Runner: failed to capture screenshot for (${step.name})`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type TraceOptions = {
* https://chromedevtools.github.io/devtools-protocol/tot/Tracing/
*/
export class Tracing {
constructor(private driver: Driver, private options: TraceOptions) {}
constructor(private driver: Driver, private options: TraceOptions) { }

async start() {
log(`Plugins: started collecting trace events`);
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/trace-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class TraceProcessor extends LighthouseTraceProcessor {
metrics: perfMetrics,
};
} catch (e) {
log(e);
log(`Plugins: error processing trace events: ${e}`);
return {};
}
}
Expand Down

0 comments on commit 41588ed

Please sign in to comment.