remove scrollbars by default (use --hide-scrollbars)

add --keepScrollbars option which keeps scrollbars in screenshots
only affects headless mode crawling
keeping scrollbars in profile creation mode
This commit is contained in:
Ilya Kreymer 2025-04-01 20:18:32 -07:00
parent fd41b32100
commit 3002fd8851
4 changed files with 26 additions and 8 deletions

View file

@ -47,6 +47,7 @@ import {
ExitCodes,
InterruptReason,
BxFunctionBindings,
ServiceWorkerOpt,
} from "./util/constants.js";
import { AdBlockRules, BlockRuleDecl, BlockRules } from "./util/blockrules.js";
@ -1626,14 +1627,14 @@ self.__bx_behaviors.selectMainBehavior();
profileUrl: this.params.profile,
headless: this.params.headless,
emulateDevice: this.emulateDevice,
swOpt: this.params.serviceWorker,
swOpt: this.params.serviceWorker as ServiceWorkerOpt,
signals: false,
chromeOptions: {
proxy: this.proxyServer,
userAgent: this.emulateDevice.userAgent,
extraArgs: this.extraChromeArgs(),
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ondisconnect: (err: any) => {
ondisconnect: (err: unknown) => {
this.markBrowserCrashed();
logger.error(
"Browser disconnected (crashed?), interrupting crawl",
@ -1643,8 +1644,9 @@ self.__bx_behaviors.selectMainBehavior();
},
recording: this.recording,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);
// keep scrollbars (for QA only)
keepScrollbars: this.params.keepScrollbars && !!this.params.qaSource,
});
// --------------
// Run Crawl Here!

View file

@ -212,6 +212,7 @@ async function main() {
],
},
recording: false,
keepScrollbars: true,
});
if (params.interactive) {

View file

@ -637,6 +637,13 @@ class ArgParser {
type: "boolean",
},
keepScrollbars: {
describe:
"if specified, will keep scrollbars for screenshots. Used for compatibility for QA",
type: "boolean",
default: false,
},
sshProxyPrivateKeyFile: {
describe:
"path to SSH private key for SOCKS5 over SSH proxy connection",

View file

@ -35,7 +35,7 @@ type BtrixChromeOpts = {
};
type LaunchOpts = {
profileUrl: string;
profileUrl?: string;
chromeOptions: BtrixChromeOpts;
signals: boolean;
headless: boolean;
@ -43,11 +43,13 @@ type LaunchOpts = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
emulateDevice?: Record<string, any>;
ondisconnect?: ((err: unknown) => NonNullable<unknown>) | null;
ondisconnect?: ((err: unknown) => void) | null;
swOpt?: ServiceWorkerOpt;
recording: boolean;
keepScrollbars: boolean;
};
// fixed height of the browser UI (may need to be adjusted in the future)
@ -97,6 +99,7 @@ export class Browser {
swOpt = "disabled",
ondisconnect = null,
recording = true,
keepScrollbars = false,
}: LaunchOpts) {
if (this.isLaunched()) {
return;
@ -125,11 +128,16 @@ export class Browser {
height: this.screenHeight - (recording ? 0 : BROWSER_HEIGHT_OFFSET),
};
const ignoreDefaultArgs = ["--enable-automation"];
if (keepScrollbars) {
ignoreDefaultArgs.push("--hide-scrollbars");
}
const launchOpts: LaunchOptions = {
args,
headless,
executablePath: this.getBrowserExe(),
ignoreDefaultArgs: ["--enable-automation", "--hide-scrollbars"],
ignoreDefaultArgs,
acceptInsecureCerts: true,
handleSIGHUP: signals,
handleSIGINT: signals,