@tocha688/browser 0.0.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { faker } from "@faker-js/faker";
2
2
  import type { BrowserResult, BrowserStartOptions } from "../types";
3
- import { startProxyServer, type ProxyServerResult } from "@tocha688/utils";
3
+ import { getIpInfo, startProxyServer, type ProxyServerResult } from "@tocha688/utils";
4
4
  import { launchBrowserBase } from "./base";
5
5
  import fs from "node:fs";
6
6
  import path from "node:path";
@@ -13,6 +13,12 @@ export async function OKBrowserStartMain(opts: BrowserStartOptions): Promise<Bro
13
13
  proxy = await startProxyServer(opts.proxy);
14
14
  console.log(`Started proxy server on port ${proxy.port}`);
15
15
  }
16
+ let ipinfo: any = proxy?.ipinfo;
17
+ if (ipinfo) {
18
+ //获取本地IP
19
+ ipinfo = await getIpInfo(ipinfo.proxy);
20
+ }
21
+
16
22
 
17
23
  const fingerprintPath = path.join(userDataDir, "fingerprint.config");
18
24
  let fingerprint: string;
@@ -71,7 +77,7 @@ export async function OKBrowserStartMain(opts: BrowserStartOptions): Promise<Bro
71
77
  "--ignores=tls",
72
78
  "--enable-logging",
73
79
  // "--proxy-server=http://127.0.0.1:" + proxy.port,
74
- "--timezone=" + (proxy?.ipinfo?.timezone ?? "America/Los_Angeles"),
80
+ "--timezone=" + (ipinfo?.timezone ?? "America/Los_Angeles"),
75
81
  "--lang=en-US",
76
82
  // "--headless", // Handled by base
77
83
  ];
@@ -1,5 +1,6 @@
1
1
  import type { ProxyFormatInfo } from "@tocha688/utils/ip";
2
2
  import * as cl from "chrome-launcher"
3
+ import type { Page } from "patchright-core";
3
4
  import * as ProxyChain from "proxy-chain";
4
5
 
5
6
  // 使用方式
@@ -14,6 +15,8 @@ export type BrowserResult = {
14
15
  port: number,
15
16
  browser: cl.LaunchedChrome,
16
17
  close: Function,
18
+ wsUrl: string,
19
+ mainPage:()=>Promise<Page>
17
20
  }
18
21
 
19
22
  export type StartBrowserFn = (opts: BrowserStartOptions) => Promise<BrowserResult>;