Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Fix chromium path for puppeteer #232

Merged
merged 5 commits into from
Dec 1, 2020
Merged
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 @@ -74,9 +74,7 @@ describe('test create visual report', () => {
const { dataUrl, fileName } = await createVisualReport(
reportParams as ReportParamsSchemaType,
queryUrl,
mockLogger,
undefined,
'./.chromium/headless_shell'
mockLogger
);
expect(fileName).toContain(`${reportParams.report_name}`);
expect(fileName).toContain('.png');
Expand All @@ -91,9 +89,7 @@ describe('test create visual report', () => {
const { dataUrl, fileName } = await createVisualReport(
reportParams as ReportParamsSchemaType,
queryUrl,
mockLogger,
undefined,
'./.chromium/headless_shell'
mockLogger
);
expect(fileName).toContain(`${reportParams.report_name}`);
expect(fileName).toContain('.pdf');
Expand Down
11 changes: 9 additions & 2 deletions kibana-reports/server/routes/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* permissions and limitations under the License.
*/

import { PLUGIN_ID } from '../../../common';

export enum FORMAT {
pdf = 'pdf',
png = 'png',
Expand Down Expand Up @@ -78,5 +80,10 @@ export const DEFAULT_REPORT_HEADER = '<h1>Open Distro Kibana Reports</h1>';

export const SECURITY_AUTH_COOKIE_NAME = 'security_authentication';

export const CHROMIUM_PATH =
'./plugins/opendistroReportsKibana/.chromium/headless_shell';
export const CHROMIUM_PATHS = [
`./plugins/${PLUGIN_ID}/.chromium/headless_shell`,
'./plugins/kibana-reports/.chromium/headless_shell',
'./.chromium/headless_shell',
`../plugins/${PLUGIN_ID}/.chromium/headless_shell`,
'../plugins/kibana-reports/.chromium/headless_shell',
];
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
REPORT_TYPE,
FORMAT,
SELECTOR,
CHROMIUM_PATH,
CHROMIUM_PATHS,
} from '../constants';
import { getFileName } from '../helpers';
import { CreateReportResultType } from '../types';
Expand All @@ -34,8 +34,7 @@ export const createVisualReport = async (
reportParams: ReportParamsSchemaType,
queryUrl: string,
logger: Logger,
cookie?: SetCookie,
chromiumPath = CHROMIUM_PATH
cookie?: SetCookie
): Promise<CreateReportResultType> => {
const {
core_params,
Expand All @@ -51,6 +50,16 @@ export const createVisualReport = async (
report_format: reportFormat,
} = coreParams;

const getChromiumPath = () => {
const path = CHROMIUM_PATHS.find((path) => {
try {
return fs.existsSync(path);
} catch (error) {}
});
if (path) return path;
logger.error('cannot find headless chromium for puppeteer');
};

// TODO: polish default header, maybe add a logo, depends on UX design
const window = new JSDOM('').window;
const DOMPurify = createDOMPurify(window);
Expand All @@ -68,7 +77,7 @@ export const createVisualReport = async (
* https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#setting-up-chrome-linux-sandbox
*/
args: ['--no-sandbox', '--disable-setuid-sandbox'],
executablePath: chromiumPath,
executablePath: getChromiumPath(),
});
const page = await browser.newPage();
page.setDefaultNavigationTimeout(0);
Expand Down