Skip to content

Commit c4546be

Browse files
authored
[Reporting/Screenshots] Do not fail the report if request is aborted (#52344) (#54596)
* [Reporting/Screenshots] Do not fail the report if request is aborted * take pageRequestFailed out of pageExit observable
1 parent f2f047b commit c4546be

File tree

1 file changed

+19
-24
lines changed
  • x-pack/legacy/plugins/reporting/server/browsers/chromium/driver_factory

1 file changed

+19
-24
lines changed

x-pack/legacy/plugins/reporting/server/browsers/chromium/driver_factory/index.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from 'puppeteer';
1616
import rimraf from 'rimraf';
1717
import * as Rx from 'rxjs';
18-
import { ignoreElements, mergeMap, tap } from 'rxjs/operators';
18+
import { ignoreElements, map, mergeMap, tap } from 'rxjs/operators';
1919
import { InnerSubscriber } from 'rxjs/internal/InnerSubscriber';
2020

2121
import { BrowserConfig, NetworkPolicy } from '../../../../types';
@@ -144,7 +144,7 @@ export class HeadlessChromiumDriverFactory {
144144
terminate$
145145
.pipe(
146146
tap(signal => {
147-
this.logger.debug(`Observer got signal: ${signal}`);
147+
this.logger.debug(`Termination signal received: ${signal}`);
148148
}),
149149
ignoreElements()
150150
)
@@ -156,7 +156,6 @@ export class HeadlessChromiumDriverFactory {
156156
this.getProcessLogger(browser).subscribe();
157157

158158
const driver$ = Rx.of(new HeadlessChromiumDriver(page, { inspect: this.browserConfig.inspect, networkPolicy: this.networkPolicy })); // prettier-ignore
159-
160159
const exit$ = this.getPageExit(browser, page);
161160

162161
observer.next({ driver$, exit$ });
@@ -177,16 +176,29 @@ export class HeadlessChromiumDriverFactory {
177176
});
178177
}
179178

180-
getBrowserLogger(page: Page): Rx.Observable<ConsoleMessage> {
181-
return Rx.fromEvent(page as NodeJS.EventEmitter, 'console').pipe(
182-
tap((line: ConsoleMessage) => {
179+
getBrowserLogger(page: Page): Rx.Observable<void> {
180+
const consoleMessages$ = Rx.fromEvent<ConsoleMessage>(page, 'console').pipe(
181+
map(line => {
183182
if (line.type() === 'error') {
184183
this.logger.error(line.text(), ['headless-browser-console']);
185184
} else {
186185
this.logger.debug(line.text(), [`headless-browser-console:${line.type()}`]);
187186
}
188187
})
189188
);
189+
190+
const pageRequestFailed$ = Rx.fromEvent<PuppeteerRequest>(page, 'requestfailed').pipe(
191+
map(req => {
192+
const failure = req.failure && req.failure();
193+
if (failure) {
194+
this.logger.warning(
195+
`Request to [${req.url()}] failed! [${failure.errorText}]. This error will be ignored.`
196+
);
197+
}
198+
})
199+
);
200+
201+
return Rx.merge(consoleMessages$, pageRequestFailed$);
190202
}
191203

192204
getProcessLogger(browser: Browser): Rx.Observable<string> {
@@ -214,18 +226,6 @@ export class HeadlessChromiumDriverFactory {
214226
mergeMap((err: Error) => Rx.throwError(err))
215227
);
216228

217-
const pageRequestFailed$: Rx.Observable<never> = Rx.fromEvent(page, 'requestfailed').pipe(
218-
mergeMap((req: PuppeteerRequest) => {
219-
const failure = req.failure && req.failure();
220-
if (failure) {
221-
return Rx.throwError(
222-
new Error(`Request to [${req.url()}] failed! [${failure.errorText}]`)
223-
);
224-
}
225-
return Rx.throwError(new Error(`Unknown failure!`));
226-
})
227-
);
228-
229229
const browserDisconnect$ = Rx.fromEvent(browser, 'disconnected').pipe(
230230
mergeMap(() =>
231231
Rx.throwError(
@@ -236,11 +236,6 @@ export class HeadlessChromiumDriverFactory {
236236
)
237237
);
238238

239-
return Rx.merge(
240-
pageError$,
241-
uncaughtExceptionPageError$,
242-
pageRequestFailed$,
243-
browserDisconnect$
244-
);
239+
return Rx.merge(pageError$, uncaughtExceptionPageError$, browserDisconnect$);
245240
}
246241
}

0 commit comments

Comments
 (0)