From 108e9c28dfaf73a2ddad424042b983c5024f50b1 Mon Sep 17 00:00:00 2001 From: rtritto Date: Sat, 24 Aug 2024 13:23:43 +0200 Subject: [PATCH 1/2] Change xvfb as optional peer dependency --- lib/cjs/index.js | 7 ++++++- lib/esm/index.mjs | 2 +- package-lock.json | 21 ++++++++++++++++----- package.json | 11 +++++++++-- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/cjs/index.js b/lib/cjs/index.js index 673df35..8b90e26 100644 --- a/lib/cjs/index.js +++ b/lib/cjs/index.js @@ -1,6 +1,11 @@ var puppeteer = require('puppeteer-core-patch') const { pageController } = require('./module/pageController.js') -const Xvfb = require('xvfb'); +let Xvfb +try { + Xvfb = require('xvfb') +} catch (error) { + // ignore +} process.env.REBROWSER_PATCHES_RUNTIME_FIX_MODE = "alwaysIsolated" // process.env.REBROWSER_PATCHES_DEBUG = 1 diff --git a/lib/esm/index.mjs b/lib/esm/index.mjs index 7742271..6aec45c 100644 --- a/lib/esm/index.mjs +++ b/lib/esm/index.mjs @@ -1,7 +1,6 @@ import { launch, Launcher } from 'chrome-launcher'; import puppeteer from 'puppeteer-core-patch'; import { pageController } from './module/pageController.mjs'; -import Xvfb from 'xvfb'; process.env.REBROWSER_PATCHES_RUNTIME_FIX_MODE = "alwaysIsolated" // process.env.REBROWSER_PATCHES_DEBUG=1 @@ -11,6 +10,7 @@ export async function connect({ args = [], headless = false, customConfig = {}, if (process.platform === 'linux' && disableXvfb === false) { try { + const { default: Xvfb } = await import('xvfb') xvfbsession = new Xvfb({ silent: true, xvfb_args: ['-screen', '0', '1920x1080x24', '-ac'] diff --git a/package-lock.json b/package-lock.json index b601ef3..282ac00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,27 @@ { "name": "puppeteer-real-browser", - "version": "1.3.5", + "version": "1.3.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "puppeteer-real-browser", - "version": "1.3.5", + "version": "1.3.6", "license": "ISC", "dependencies": { "chrome-launcher": "^1.1.2", "ghost-cursor": "^1.3.0", "puppeteer-core-patch": "^1.0.1", "puppeteer-extra": "^3.3.6", - "tree-kill": "^1.2.2", - "xvfb": "^0.4.0" + "tree-kill": "^1.2.2" + }, + "peerDependencies": { + "xvfb": "*" + }, + "peerDependenciesMeta": { + "xvfb": { + "optional": true + } } }, "node_modules/@tootallnate/quickjs-emscripten": { @@ -703,7 +710,8 @@ "resolved": "https://registry.npmjs.org/nan/-/nan-2.20.0.tgz", "integrity": "sha512-bk3gXBZDGILuuo/6sKtr0DQmSThYHLtNCdSdXk9YkxD/jK6X2vmCyyXBBxyqZ4XcnzTyYEAThfX3DCEnLf6igw==", "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/netmask": { "version": "2.0.2", @@ -921,6 +929,7 @@ "hasInstallScript": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "nan": "^2.13.2" }, @@ -1157,6 +1166,8 @@ "resolved": "https://registry.npmjs.org/xvfb/-/xvfb-0.4.0.tgz", "integrity": "sha512-g55AbjcBL4Bztfn7kiUrR0ne8mMUsFODDJ+HFGf5OuHJqKKccpExX2Qgn7VF2eImw1eoh6+riXHser1J4agrFA==", "license": "MIT", + "optional": true, + "peer": true, "optionalDependencies": { "sleep": "6.1.0" } diff --git a/package.json b/package.json index 9337e82..0c22f5c 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,15 @@ "ghost-cursor": "^1.3.0", "puppeteer-core-patch": "^1.0.1", "puppeteer-extra": "^3.3.6", - "tree-kill": "^1.2.2", - "xvfb": "^0.4.0" + "tree-kill": "^1.2.2" + }, + "peerDependencies": { + "xvfb": "*" + }, + "peerDependenciesMeta": { + "xvfb": { + "optional": true + } }, "repository": { "type": "git", From 2e51b19c550e9c7dfcfa2cab22dca2bd120ce297 Mon Sep 17 00:00:00 2001 From: rtritto Date: Thu, 29 Aug 2024 13:16:16 +0000 Subject: [PATCH 2/2] Add xvfb to dev dependencies --- package-lock.json | 12 +++++++----- package.json | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 282ac00..275ea29 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,9 @@ "puppeteer-extra": "^3.3.6", "tree-kill": "^1.2.2" }, + "devDependencies": { + "xvfb": "^0.4.0" + }, "peerDependencies": { "xvfb": "*" }, @@ -709,9 +712,9 @@ "version": "2.20.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.20.0.tgz", "integrity": "sha512-bk3gXBZDGILuuo/6sKtr0DQmSThYHLtNCdSdXk9YkxD/jK6X2vmCyyXBBxyqZ4XcnzTyYEAThfX3DCEnLf6igw==", + "dev": true, "license": "MIT", - "optional": true, - "peer": true + "optional": true }, "node_modules/netmask": { "version": "2.0.2", @@ -926,10 +929,10 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/sleep/-/sleep-6.1.0.tgz", "integrity": "sha512-Z1x4JjJxsru75Tqn8F4tnOFeEu3HjtITTsumYUiuz54sGKdISgLCek9AUlXlVVrkhltRFhNUsJDJE76SFHTDIQ==", + "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, - "peer": true, "dependencies": { "nan": "^2.13.2" }, @@ -1165,9 +1168,8 @@ "version": "0.4.0", "resolved": "https://registry.npmjs.org/xvfb/-/xvfb-0.4.0.tgz", "integrity": "sha512-g55AbjcBL4Bztfn7kiUrR0ne8mMUsFODDJ+HFGf5OuHJqKKccpExX2Qgn7VF2eImw1eoh6+riXHser1J4agrFA==", + "dev": true, "license": "MIT", - "optional": true, - "peer": true, "optionalDependencies": { "sleep": "6.1.0" } diff --git a/package.json b/package.json index 0c22f5c..21e8340 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,9 @@ "puppeteer-extra": "^3.3.6", "tree-kill": "^1.2.2" }, + "devDependencies": { + "xvfb": "^0.4.0" + }, "peerDependencies": { "xvfb": "*" },