/*
package cn.sikey.selenium.util;

import com.microsoft.playwright.*;
import com.microsoft.playwright.impl.PlaywrightImpl;

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.microsoft.playwright.*;
import java.util.Map;
import java.util.Collections;

*/
/**
 * @Author: nelson
 * @Date: 2025/7/1
 * @Description:
 *//*

public class CustomPlaywrightFactory {

    public CustomPlaywrightFactory(){
        // 设置系统属性
        System.setProperty("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", "1");
        System.setProperty("PLAYWRIGHT_DISABLE_INSTALLATION_METRICS", "1");

        // 设置环境变量（使用反射）
        try {
            Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
            Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
            theEnvironmentField.setAccessible(true);
            Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null);
            env.put("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", "1");
            env.put("PLAYWRIGHT_DISABLE_INSTALLATION_METRICS", "1");
        } catch (Exception e) {
            // 备选方案：使用 System.getenv() 的可写 Map
            try {
                Map<String, String> env = System.getenv();
                Field field = env.getClass().getDeclaredField("m");
                field.setAccessible(true);
                Map<String, String> writableEnv = (Map<String, String>) field.get(env);
                writableEnv.put("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", "1");
                writableEnv.put("PLAYWRIGHT_DISABLE_INSTALLATION_METRICS", "1");
            } catch (Exception ex) {
                throw new RuntimeException("无法设置环境变量", ex);
            }
        }
    }


    // 使用官方公共 API 创建 Playwright 实例
    public  static  Playwright createPlaywright() {
        // 使用 Playwright 的工厂方法并传递环境变量
        return Playwright.create(new Playwright.CreateOptions() {
            public Map<String, String> getEnv() {
                return Collections.unmodifiableMap(Map.of(
                        "PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", "1",
                        "PLAYWRIGHT_DISABLE_INSTALLATION_METRICS", "1"
                ));
            }
        });
    }
}
*/
