reduced .exe size

This commit is contained in:
2026-01-09 18:54:39 +01:00
parent 27a4239a4d
commit 1e85de8db6
4 changed files with 19 additions and 8729 deletions

View File

@@ -1,6 +1,6 @@
const path = require("path");
const fs = require("fs");
const { chromium } = require("playwright-core");
const { chromium } = require("playwright");
const {spawn} = require("node:child_process");
let browser;
let context;
@@ -9,36 +9,31 @@ const BLOCK_LIST = [
"adsystem", "analytics", "tracker", "pixel", "quantserve", "newrelic"
];
function isPackaged() {
return process.env.IS_PACKAGED === "true";
function runHidden(cmd, args) {
return new Promise((res, rej) => {
const p = spawn(cmd, args, {
stdio: "ignore",
shell: true,
windowsHide: true
});
p.on("exit", c => c === 0 ? res() : rej(new Error("exit " + c)));
});
}
function getChromiumPath() {
if (isPackaged()) {
return path.join(
process.resourcesPath,
"playwright",
"chromium",
"chrome-headless-shell-win64",
"chrome-headless-shell.exe"
);
}
async function ensureChromiumShell() {
const exe = chromium.executablePath();
if (exe && fs.existsSync(exe)) return;
return chromium.executablePath();
await runHidden("npx", ["playwright", "install", "chromium-headless-shell"]);
}
async function initHeadless() {
if (browser) return;
const exePath = getChromiumPath();
if (!fs.existsSync(exePath)) {
throw new Error("Chromium not found: " + exePath);
}
await ensureChromiumShell();
browser = await chromium.launch({
headless: true,
executablePath: exePath,
args: [
"--no-sandbox",
"--disable-setuid-sandbox",