From 47502227342144df22cbbc7cb168b1ee365c9841 Mon Sep 17 00:00:00 2001 From: "paulina.shakirova" Date: Sat, 19 Oct 2024 16:55:12 +0200 Subject: [PATCH 1/3] refactor: remove unused setup code to connect to remote debugger --- .../src/config/index.ts | 5 ---- x-pack/plugins/screenshotting/README.md | 1 - .../server/browsers/chromium/driver.ts | 24 ------------------- .../browsers/chromium/driver_factory/index.ts | 2 +- 4 files changed, 1 insertion(+), 31 deletions(-) diff --git a/packages/kbn-screenshotting-server/src/config/index.ts b/packages/kbn-screenshotting-server/src/config/index.ts index 292787ceb16dc..dc75304f71483 100644 --- a/packages/kbn-screenshotting-server/src/config/index.ts +++ b/packages/kbn-screenshotting-server/src/config/index.ts @@ -34,11 +34,6 @@ export const config: PluginConfigDescriptor = { 'xpack.screenshotting.browser.autoDownload', { level: 'warning' } ), - renameFromRoot( - 'xpack.reporting.capture.browser.chromium.inspect', - 'xpack.screenshotting.browser.chromium.inspect', - { level: 'warning' } - ), renameFromRoot( 'xpack.reporting.capture.browser.chromium.disableSandbox', 'xpack.screenshotting.browser.chromium.disableSandbox', diff --git a/x-pack/plugins/screenshotting/README.md b/x-pack/plugins/screenshotting/README.md index 04b7d07f223c4..8138be53dc8f4 100644 --- a/x-pack/plugins/screenshotting/README.md +++ b/x-pack/plugins/screenshotting/README.md @@ -106,7 +106,6 @@ Option | Default | Description `xpack.screenshotting.networkPolicy.enabled` | `true` | Capturing a screenshot from a Kibana page involves sending out requests for all the linked web assets. For example, a Markdown visualization can show an image from a remote server. `xpack.screenshotting.networkPolicy.rules` | Allow http, https, ws, wss, and data. | A policy is specified as an array of objects that describe what to allow or deny based on a host or protocol. If a host or protocol is not specified, the rule matches any host or protocol. `xpack.screenshotting.browser.autoDownload` | Depends on the `dist` parameter. | Flag to automatically download chromium distribution. -`xpack.screenshotting.browser.chromium.inspect` | Depends on the `dist` parameter. | Connects to the browser over a pipe instead of a WebSocket. See [puppeteer](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#puppeteerlaunchoptions) documentation. `xpack.screenshotting.browser.chromium.disableSandbox` | Defaults to `false` for all operating systems except Debian and Red Hat Linux, which use `true`. | It is recommended that you research the feasibility of enabling unprivileged user namespaces. An exception is if you are running Kibana in Docker because the container runs in a user namespace with the built-in seccomp/bpf filters. For more information, refer to [Chromium sandbox](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/linux/sandboxing.md). `xpack.screenshotting.browser.chromium.proxy.enabled` | `false` | Enables the proxy for Chromium to use. `xpack.screenshotting.browser.chromium.proxy.server` | _none_ | The uri for the proxy server. Providing the username and password for the proxy server via the uri is not supported. diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts index 3c199b2916b30..0365ae03ab7de 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts @@ -140,10 +140,6 @@ export class HeadlessChromiumDriver { this.registerListeners(url, headers, logger); await this.page.goto(url, { waitUntil: 'domcontentloaded' }); - if (this.config.browser.chromium.inspect) { - await this.launchDebugger(); - } - await this.waitForSelector( pageLoadSelector, { timeout }, @@ -452,26 +448,6 @@ export class HeadlessChromiumDriver { this.listenersAttached = true; } - private async launchDebugger() { - // In order to pause on execution we have to reach more deeply into Chromiums Devtools Protocol, - // and more specifically, for the page being used. _client is per-page. - // In order to get the inspector running, we have to know the page's internal ID (again, private) - // in order to construct the final debugging URL. - - const client = this.page._client(); - const target = this.page.target(); - const targetId = target._targetId; - - await client.send('Debugger.enable'); - await client.send('Debugger.pause'); - const wsEndpoint = this.page.browser().wsEndpoint(); - const { port } = parseUrl(wsEndpoint); - - await open( - `http://localhost:${port}/devtools/inspector.html?ws=localhost:${port}/devtools/page/${targetId}` - ); - } - private _shouldUseCustomHeaders(sourceUrl: string, targetUrl: string) { const { hostname: sourceHostname, diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts index d8503b70ad963..073fa12c88066 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver_factory/index.ts @@ -147,7 +147,7 @@ export class HeadlessChromiumDriverFactory { let browser: Browser | undefined; try { browser = await puppeteer.launch({ - pipe: !this.config.browser.chromium.inspect, + pipe: true, userDataDir: this.userDataDir, executablePath: this.binaryPath, acceptInsecureCerts: true, From c94c235075e042feeff1e5be48da4586fb73a7bc Mon Sep 17 00:00:00 2001 From: "paulina.shakirova" Date: Tue, 22 Oct 2024 19:39:22 +0200 Subject: [PATCH 2/3] update schema and tests based on comment part1 --- package.json | 2 -- packages/kbn-screenshotting-server/src/config/schema.ts | 6 ------ .../docker_generator/resources/base/bin/kibana-docker | 1 - .../screenshotting/server/browsers/chromium/driver.ts | 1 - x-pack/plugins/screenshotting/server/config/schema.test.ts | 1 - 5 files changed, 11 deletions(-) diff --git a/package.json b/package.json index 5d287321faec9..2b3f3c9fb8363 100644 --- a/package.json +++ b/package.json @@ -1190,7 +1190,6 @@ "object-path-immutable": "^3.1.1", "openai": "^4.24.1", "openpgp": "5.10.1", - "opn": "^5.5.0", "ora": "^4.0.4", "p-limit": "^3.0.1", "p-map": "^4.0.0", @@ -1611,7 +1610,6 @@ "@types/normalize-path": "^3.0.0", "@types/nunjucks": "^3.2.6", "@types/object-hash": "^1.3.0", - "@types/opn": "^5.1.0", "@types/ora": "^1.3.5", "@types/papaparse": "^5.0.3", "@types/pbf": "3.0.2", diff --git a/packages/kbn-screenshotting-server/src/config/schema.ts b/packages/kbn-screenshotting-server/src/config/schema.ts index e63d3737013bf..db6899303f871 100644 --- a/packages/kbn-screenshotting-server/src/config/schema.ts +++ b/packages/kbn-screenshotting-server/src/config/schema.ts @@ -50,12 +50,6 @@ export const ConfigSchema = schema.object({ schema.boolean({ defaultValue: true }) ), chromium: schema.object({ - inspect: schema.conditional( - schema.contextRef('dist'), - true, - schema.boolean({ defaultValue: false }), - schema.maybe(schema.never()) - ), disableSandbox: schema.maybe(schema.boolean()), // default value is dynamic in createConfig proxy: schema.object({ enabled: schema.boolean({ defaultValue: false }), diff --git a/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker b/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker index 3c1e7ebe857fa..fbe64258a5704 100755 --- a/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker +++ b/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker @@ -321,7 +321,6 @@ kibana_vars=( xpack.observability.unsafe.thresholdRule.enabled xpack.reporting.capture.browser.autoDownload xpack.reporting.capture.browser.chromium.disableSandbox - xpack.reporting.capture.browser.chromium.inspect xpack.reporting.capture.browser.chromium.maxScreenshotDimension xpack.reporting.capture.browser.chromium.proxy.bypass xpack.reporting.capture.browser.chromium.proxy.enabled diff --git a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts index 0365ae03ab7de..6b7cfdd359895 100644 --- a/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts +++ b/x-pack/plugins/screenshotting/server/browsers/chromium/driver.ts @@ -12,7 +12,6 @@ import { } from '@kbn/screenshot-mode-plugin/server'; import { ConfigType } from '@kbn/screenshotting-server'; import { truncate } from 'lodash'; -import open from 'opn'; import { ElementHandle, EvaluateFunc, HTTPResponse, Page } from 'puppeteer'; import { Subject } from 'rxjs'; import { parse as parseUrl } from 'url'; diff --git a/x-pack/plugins/screenshotting/server/config/schema.test.ts b/x-pack/plugins/screenshotting/server/config/schema.test.ts index 18ef1aa41415c..0b72b79bdcd66 100644 --- a/x-pack/plugins/screenshotting/server/config/schema.test.ts +++ b/x-pack/plugins/screenshotting/server/config/schema.test.ts @@ -74,7 +74,6 @@ describe('ConfigSchema', () => { "browser": Object { "autoDownload": false, "chromium": Object { - "inspect": false, "proxy": Object { "enabled": false, }, From 3db2382bc24150f740b72758161b4adc6086143f Mon Sep 17 00:00:00 2001 From: "paulina.shakirova" Date: Tue, 22 Oct 2024 19:39:44 +0200 Subject: [PATCH 3/3] remove unused opn and types/opn dep --- yarn.lock | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/yarn.lock b/yarn.lock index 7da3bf122f483..65c838b0cbe23 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11096,13 +11096,6 @@ dependencies: "@types/node" "*" -"@types/opn@^5.1.0": - version "5.1.0" - resolved "https://registry.yarnpkg.com/@types/opn/-/opn-5.1.0.tgz#bff7bc371677f4bdbb37884400e03fd81f743927" - integrity sha512-TNPrB7Y1xl06zDI0aGyqkgxjhIev3oJ+cdqlZ52MTAHauWpEL/gIUdHebIfRHFZk9IqSBpE2ci1DT48iZH81yg== - dependencies: - "@types/node" "*" - "@types/ora@^1.3.5": version "1.3.5" resolved "https://registry.yarnpkg.com/@types/ora/-/ora-1.3.5.tgz#1a08bf64902c1473d3d47de58549a49e07140f1c" @@ -24901,13 +24894,6 @@ opentracing@^0.14.3: resolved "https://registry.yarnpkg.com/opentracing/-/opentracing-0.14.4.tgz#a113408ea740da3a90fde5b3b0011a375c2e4268" integrity sha512-nNnZDkUNExBwEpb7LZaeMeQgvrlO8l4bgY/LvGNZCR0xG/dGWqHqjKrAmR5GUoYo0FIz38kxasvA1aevxWs2CA== -opn@^5.5.0: - version "5.5.0" - resolved "https://registry.yarnpkg.com/opn/-/opn-5.5.0.tgz#fc7164fab56d235904c51c3b27da6758ca3b9bfc" - integrity sha512-PqHpggC9bLV0VeWcdKhkpxY+3JTzetLSqTCWL/z/tFIbI6G8JCjondXklT1JinczLz2Xib62sSp0T/gKT4KksA== - dependencies: - is-wsl "^1.1.0" - optional-js@^2.0.0: version "2.1.1" resolved "https://registry.yarnpkg.com/optional-js/-/optional-js-2.1.1.tgz#c2dc519ad119648510b4d241dbb60b1167c36a46"