"use strict";

/** 与 zhenqianba Electron 版 COMMON_BROWSER_ARGS / STEALTH 对齐 */

const COMMON_BROWSER_ARGS = [
  "--disable-blink-features=AutomationControlled",
  "--no-sandbox",
  "--disable-setuid-sandbox",
  "--disable-dev-shm-usage",
  "--disable-infobars",
  "--no-first-run",
  "--no-default-browser-check",
  "--disable-breakpad",
  "--disable-component-update",
  "--disable-sync",
  "--disable-default-apps",
  "--disable-popup-blocking",
  "--disable-background-networking",
  "--disable-background-timer-throttling",
  "--disable-renderer-backgrounding",
  "--disable-backgrounding-occluded-windows",
  "--enable-gpu",
  "--enable-webgl",
  "--ignore-gpu-blacklist",
  "--enable-accelerated-video-decode",
  "--enable-gpu-rasterization",
  "--enable-proprietary-codecs",
  "--autoplay-policy=no-user-gesture-required",
  "--disable-features=IsolateOrigins,site-per-process",
];

const BROWSER_IGNORE_DEFAULT_ARGS = ["--enable-automation"];

const STEALTH_INIT_SCRIPT = `
  Object.defineProperty(navigator, 'webdriver', {
    get: () => undefined,
    configurable: true
  });
  window.chrome = {
    runtime: {
      connect: function() { return { onDisconnect: { addListener: function() {} }, onMessage: { addListener: function() {} }, postMessage: function() {}, disconnect: function() {} }; },
      sendMessage: function() {},
      id: undefined
    },
    loadTimes: function() { return { firstPaintTime: 0, startLoadTime: 0, commitLoadTime: 0, finishDocumentLoadTime: 0, finishLoadTime: 0, firstPaintAfterLoadTime: 0, navigationType: 'Other', requestTime: Date.now() / 1000 }; },
    csi: function() { return { startE: Date.now(), onloadT: Date.now(), pageT: Math.random() * 1000 + 500, tran: 15 }; },
    app: { isInstalled: false }
  };
  Object.defineProperty(navigator, 'plugins', {
    get: () => [{ name: 'Chrome PDF Plugin', description: 'Portable Document Format', filename: 'internal-pdf-viewer', length: 1 }],
    configurable: true
  });
  Object.defineProperty(navigator, 'languages', {
    get: () => ['zh-CN', 'zh', 'en'],
    configurable: true
  });
  delete window.__playwright;
  delete window.__pw_manual;
  delete window.webdriver;
`;

const DEFAULT_USER_AGENT =
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";

module.exports = {
  COMMON_BROWSER_ARGS,
  BROWSER_IGNORE_DEFAULT_ARGS,
  STEALTH_INIT_SCRIPT,
  DEFAULT_USER_AGENT,
};
