import { chromium } from "playwright";
import os from "os";
import fs from "fs";
import path from "path";

const __dirname = new URL(".", import.meta.url).pathname;
const userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), "myapp"));
const pathToExtension = path.join(
    __dirname,
    "fngmhnnpilhplaeedifhccceomclgfbg"
);

// 启动浏览器
const context = await chromium.launchPersistentContext(userDataDir, {
    headless: false,
    // proxy: {
    //     server: "199.188.92.93:8000",
    //     username: "proxy",
    //     password: "rPZHv9U",
    // },
    args: [
        `--disable-extensions-except=${pathToExtension}`,
        `--load-extension=${pathToExtension}`,
    ],
    userAgent:
        "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3105.3 Safari/537.36",
});

// 创建一个新的浏览器页面
const page = await context.newPage();