Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
* you may not use this file except in compliance with the Elastic License.
*/

export interface IArgOptions {
userDataDir: string;
viewport: { width: number; height: number };
disableSandbox: boolean;
proxyConfig: {
enabled: boolean;
server: string;
bypass?: string[];
};
verboseLogging?: boolean;
import { BrowserConfig } from '../../../../types';

interface LaunchArgs {
userDataDir: BrowserConfig['userDataDir'];
viewport: BrowserConfig['viewport'];
disableSandbox: BrowserConfig['disableSandbox'];
proxy: BrowserConfig['proxy'];
verboseLogging: BrowserConfig['verboseLogging'];
}

export const args = ({
userDataDir,
viewport,
disableSandbox,
proxyConfig,
proxy: proxyConfig,
verboseLogging,
}: IArgOptions) => {
}: LaunchArgs) => {
const flags = [
// Disable built-in Google Translate service
'--disable-translate',
Expand Down Expand Up @@ -61,6 +59,7 @@ export const args = ({
flags.push('--no-sandbox');
}

// Dead code?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a bug to wrap this in a conditional. I think we want the logging flags hardcoded to "on":

https://www.chromium.org/for-testers/enable-logging

if (verboseLogging) {
flags.push('--enable-logging');
flags.push('--v=1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,80 +13,79 @@ import {
ConsoleMessage,
Request as PuppeteerRequest,
} from 'puppeteer';
import { ChildProcess } from 'child_process';
import rimraf from 'rimraf';
import * as Rx from 'rxjs';
import { ignoreElements, mergeMap, tap } from 'rxjs/operators';
import { InnerSubscriber } from 'rxjs/internal/InnerSubscriber';

import { puppeteerLaunch } from '../puppeteer';
import { BrowserConfig } from '../../../../types';
import { LevelLogger as Logger } from '../../../lib/level_logger';
import { HeadlessChromiumDriver } from '../driver';
import { args, IArgOptions } from './args';
import { safeChildProcess } from '../../safe_child_process';
import { puppeteerLaunch } from '../puppeteer';
import { getChromeLogLocation } from '../paths';
import { args } from './args';

type binaryPath = string;
type queueTimeout = number;
interface IBrowserConfig {
[key: string]: any;
}

export class HeadlessChromiumDriverFactory {
private binaryPath: binaryPath;
private logger: Logger;
private browserConfig: IBrowserConfig;
private browserConfig: BrowserConfig;
private queueTimeout: queueTimeout;

constructor(
binaryPath: binaryPath,
logger: Logger,
browserConfig: IBrowserConfig,
browserConfig: BrowserConfig,
queueTimeout: queueTimeout
) {
this.binaryPath = binaryPath;
this.browserConfig = browserConfig;
this.queueTimeout = queueTimeout;
this.logger = logger;
this.logger = logger; // TODO: just pass logger into each method from outside, like test() has it
}

type = 'chromium';

test(
{ viewport, browserTimezone }: { viewport: IArgOptions['viewport']; browserTimezone: string },
logger: Logger
) {
test({ viewport }: { viewport: BrowserConfig['viewport'] }, logger: Logger) {
const userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'chromium-'));
const chromiumArgs = args({
userDataDir,
viewport,
verboseLogging: true,
disableSandbox: this.browserConfig.disableSandbox,
proxyConfig: this.browserConfig.proxy,
proxy: this.browserConfig.proxy,
});

return puppeteerLaunch({
userDataDir,
executablePath: this.binaryPath,
ignoreHTTPSErrors: true,
args: chromiumArgs,
env: {
TZ: browserTimezone,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

browserTimezone wasn't getting passed

},
} as LaunchOptions).catch((error: Error) => {
logger.error(
`The Reporting plugin encountered issues launching Chromium in a self-test. You may have trouble generating reports.`
);
logger.error(error);
logger.warning(`See Chromium's log output at "${getChromeLogLocation(this.binaryPath)}"`);
return null;
});
} as LaunchOptions)
.then((browser: Browser) => {
const childProcess: ChildProcess = browser.process();
logger.debug(`Test browser process launched with PID: ${childProcess.pid}`);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 1/2 of the actual changes. Everything else is due to increase strictness of Typescript

return browser;
})
.catch((error: Error) => {
logger.error(
`The Reporting plugin encountered issues launching Chromium in a self-test. You may have trouble generating reports.`
);
logger.error(error);
logger.warning(`See Chromium's log output at "${getChromeLogLocation(this.binaryPath)}"`);
return null;
});
}

create({
viewport,
browserTimezone,
}: {
viewport: IArgOptions['viewport'];
viewport: BrowserConfig['viewport'];
browserTimezone: string;
}): Rx.Observable<{
driver$: Rx.Observable<HeadlessChromiumDriver>;
Expand All @@ -101,7 +100,7 @@ export class HeadlessChromiumDriverFactory {
viewport,
verboseLogging: this.logger.isVerbose,
disableSandbox: this.browserConfig.disableSandbox,
proxyConfig: this.browserConfig.proxy,
Copy link
Copy Markdown
Member Author

@tsullivan tsullivan Sep 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might have been hiding a bug. If it is meant to match the Reporting Settings, then it should be proxy: https://www.elastic.co/guide/en/kibana/current/reporting-settings-kb.html#reporting-chromium-settings

proxy: this.browserConfig.proxy,
});

let browser: Browser;
Expand All @@ -118,6 +117,10 @@ export class HeadlessChromiumDriverFactory {
},
} as LaunchOptions);

// log the child process PID
const childProcess: ChildProcess = browser.process();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 2/2 of the actual changes. Everything else is due to increase strictness of Typescript

this.logger.debug(`Job browser process launched with PID: ${childProcess.pid}`);

page = await browser.newPage();

// All navigation/waitFor methods default to 30 seconds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { LevelLogger } from '../../lib';
import { HeadlessChromiumDriverFactory } from './driver_factory';
import { BrowserConfig } from '../../../types';

export { paths } from './paths';

export async function createDriverFactory(binaryPath, logger, browserConfig, queueTimeout) {
export async function createDriverFactory(
binaryPath: string,
logger: LevelLogger,
browserConfig: BrowserConfig,
queueTimeout: number
): Promise<HeadlessChromiumDriverFactory> {
return new HeadlessChromiumDriverFactory(binaryPath, logger, browserConfig, queueTimeout);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import { installBrowser } from './install';
import { LevelLogger } from '../lib/level_logger';
import { KbnServer } from '../../types';
import { PLUGIN_ID } from '../../common/constants';
import { HeadlessChromiumDriverFactory } from './chromium/driver_factory';

export async function createBrowserDriverFactory(server: KbnServer) {
export async function createBrowserDriverFactory(
server: KbnServer
): Promise<HeadlessChromiumDriverFactory> {
const config = server.config();
const logger = LevelLogger.createForServer(server, [PLUGIN_ID, 'browser-driver']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
import { Browser } from 'puppeteer';
import { KbnServer, Logger } from '../../../types';
import { CHROMIUM } from '../../browsers/browser_types';
import { HeadlessChromiumDriverFactory } from '../../browsers/chromium/driver_factory';

/*
* Validate the Reporting headless browser can launch, and that it can connect
* to the locally running Kibana instance.
*/
export const validateBrowser = async (server: KbnServer, browserFactory: any, logger: Logger) => {
export const validateBrowser = async (
server: KbnServer,
browserFactory: HeadlessChromiumDriverFactory,
logger: Logger
) => {
if (browserFactory.type === CHROMIUM) {
return browserFactory
.test(
{
viewport: { width: 800, height: 600 },
},
logger
)
.test({ viewport: { width: 800, height: 600 } }, logger)
.then((browser: Browser | null) => {
if (browser && browser.close) {
browser.close();
Expand Down
13 changes: 13 additions & 0 deletions x-pack/legacy/plugins/reporting/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ export interface ConfigObject {
get: (path?: string) => any;
}

export interface BrowserConfig {
inspect: boolean;
userDataDir: string;
viewport: { width: number; height: number };
disableSandbox: boolean;
proxy: {
enabled: boolean;
server: string;
bypass?: string[];
};
verboseLogging?: boolean;
}

export interface ElementPosition {
boundingClientRect: {
// modern browsers support x/y, but older ones don't
Expand Down