diff --git a/kibana-reports/server/routes/utils/__tests__/visualReportHelper.test.ts b/kibana-reports/server/routes/utils/__tests__/visualReportHelper.test.ts index fdcd6c9f..e015bb5a 100644 --- a/kibana-reports/server/routes/utils/__tests__/visualReportHelper.test.ts +++ b/kibana-reports/server/routes/utils/__tests__/visualReportHelper.test.ts @@ -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'); @@ -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'); diff --git a/kibana-reports/server/routes/utils/constants.ts b/kibana-reports/server/routes/utils/constants.ts index 6e5a28ea..c165d7b5 100644 --- a/kibana-reports/server/routes/utils/constants.ts +++ b/kibana-reports/server/routes/utils/constants.ts @@ -13,6 +13,8 @@ * permissions and limitations under the License. */ +import { PLUGIN_ID } from '../../../common'; + export enum FORMAT { pdf = 'pdf', png = 'png', @@ -78,5 +80,10 @@ export const DEFAULT_REPORT_HEADER = '

Open Distro Kibana Reports

'; 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', +]; diff --git a/kibana-reports/server/routes/utils/visual_report/visualReportHelper.ts b/kibana-reports/server/routes/utils/visual_report/visualReportHelper.ts index d154be85..bd8c00b7 100644 --- a/kibana-reports/server/routes/utils/visual_report/visualReportHelper.ts +++ b/kibana-reports/server/routes/utils/visual_report/visualReportHelper.ts @@ -22,7 +22,7 @@ import { REPORT_TYPE, FORMAT, SELECTOR, - CHROMIUM_PATH, + CHROMIUM_PATHS, } from '../constants'; import { getFileName } from '../helpers'; import { CreateReportResultType } from '../types'; @@ -34,8 +34,7 @@ export const createVisualReport = async ( reportParams: ReportParamsSchemaType, queryUrl: string, logger: Logger, - cookie?: SetCookie, - chromiumPath = CHROMIUM_PATH + cookie?: SetCookie ): Promise => { const { core_params, @@ -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); @@ -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);