@tocha688/browser 1.0.1 → 1.0.3
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.
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/package.json +2 -2
- package/src/human/helpert.ts +10 -0
- package/src/network/cache.ts +3 -2
- package/src/providers/base.ts +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Re=Object.create;var N=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Me=Object.getOwnPropertyNames;var Te=Object.getPrototypeOf,Ve=Object.prototype.hasOwnProperty;var Ce=(o,t)=>{for(var e in t)N(o,e,{get:t[e],enumerable:!0})},K=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Me(t))!Ve.call(o,i)&&i!==e&&N(o,i,{get:()=>t[i],enumerable:!(r=ke(t,i))||r.enumerable});return o};var g=(o,t,e)=>(e=o!=null?Re(Te(o)):{},K(t||!o||!o.__esModule?N(e,"default",{value:o,enumerable:!0}):e,o)),Be=o=>K(N({},"__esModule",{value:!0}),o);var rt={};Ce(rt,{AdsBrowserStartMain:()=>et,AutoHelper:()=>L,BrowserCachePath:()=>je,BrowserPool:()=>X,Cpus:()=>q,HumanMouse:()=>F,LinuxWebGL:()=>Ze,Memorys:()=>Qe,OKBrowserCreate:()=>tt,OKBrowserStartMain:()=>Se,PcScreen:()=>$,WindowsWebGL:()=>j,createBrowser:()=>k,fetchResource:()=>xe,getBrowserWebSocketUrl:()=>P,isElementFocused:()=>O,isLocator:()=>x,launchBrowserBase:()=>G,makeUniqueBrowserConfig:()=>H,rSysFonts:()=>z,routeAssetsAbort:()=>Ke,routeAssetsCache:()=>ze,routeAssetsLocal:()=>Je,splitTextIntoChunks:()=>R,startLocalBrowser:()=>Ye});module.exports=Be(rt);var v=require("@tocha688/utils"),S=require("@tocha688/utils/random"),Y=require("bezier-js"),F=class{page;currentPosition={x:0,y:0};config={minSteps:15,maxSteps:50};constructor(t,e={}){this.page=t,this.currentPosition={x:0,y:0},this.config={minSteps:15,maxSteps:50,...e}}_randomSteps(){return Math.floor(Math.random()*(this.config.maxSteps-this.config.minSteps))+this.config.minSteps}async _toPoint(t,e){let{min:r=.2,max:i=.8}=e||{},s=await t.boundingBox();if(!s)throw new Error("Element has no bounding box");return{x:s.x+s.width*(r+Math.random()*(i-r)),y:s.y+s.height*(r+Math.random()*(i-r))}}async moveTo(t,e,r={}){let{speed:i=.5,randomness:s=.3}=r,n=this.currentPosition,c={x:t,y:e},a=this.generateControlPoints(n,c,s),p=new Y.Bezier(...a),l=r.steps||this._randomSteps(),u=p.getLUT(l);for(let m=0;m<u.length;m++){let h=u[m],B=this.getDynamicDelay(m,u.length,i);await this.page.mouse.move(h.x,h.y),await(0,v.sleep)(B)}this.currentPosition=c}async moveToEl(t,e={}){let r=await this._toPoint(t,e);await this.moveTo(r.x,r.y,e)}async moveBy(t,e,r={}){let i=this.currentPosition.x+t,s=this.currentPosition.y+e;return this.moveTo(i,s,r)}async scrollBy(t,e={}){let{speed:r=.5,randomness:i=.3}=e,s=e.steps||this._randomSteps(),n=t/s;for(let c=0;c<s;c++){let a=n*(Math.random()-.5)*i,p=n+a;await this.page.evaluate("(y) => { window.scrollBy(0, y); }",p);let l=this.getDynamicDelay(c,s,r);await(0,v.sleep)(l)}}async scrollTo(t,e={}){let r=await this.page.evaluate("() => window.scrollY || document.documentElement.scrollTop || 0"),i=t-r;Math.abs(i)<1||await this.scrollBy(i,e)}async scrollToEl(t,e={}){let i=this.page.viewportSize()?.height??await this.page.evaluate("() => window.innerHeight"),s=await t.evaluate(`(node) => {
|
|
2
2
|
const rect = node.getBoundingClientRect();
|
|
3
3
|
return { top: rect.top + window.scrollY, height: rect.height };
|
|
4
4
|
}`),n=Math.max(0,s.top-i*.3);await this.scrollTo(n,e)}async click(t,e,r={}){let{doubleClick:i=!1,button:s="left"}=r;await this.moveTo(t,e,{steps:r.steps,speed:r.speed,randomness:r.randomness}),await this.page.mouse.down({button:s}),await(0,v.sleep)((0,S.rInt)(50,150)),await this.page.mouse.up({button:s}),i&&(await(0,v.sleep)((0,S.rInt)(100,300)),await this.page.mouse.down({button:s}),await(0,v.sleep)((0,S.rInt)(50,150)),await this.page.mouse.up({button:s}))}async clickEl(t,e={}){try{let r=await this._toPoint(t,e);await this.click(r.x,r.y,e)}catch(r){console.log("clickEl err: ",r,"el: ",t)}}generateControlPoints(t,e,r){let i=Math.hypot(e.x-t.x,e.y-t.y),s={x:t.x+(e.x-t.x)*.3+(Math.random()-.5)*i*r,y:t.y+(e.y-t.y)*.3+(Math.random()-.5)*i*r},n={x:e.x-(e.x-t.x)*.3+(Math.random()-.5)*i*r,y:e.y-(e.y-t.y)*.3+(Math.random()-.5)*i*r};return[t,s,n,e]}getDynamicDelay(t,e,r){let i=t/e,s=10+(1-r)*50;return Math.max(10,s*(1-Math.sin(i*Math.PI))*.5)}getRandomDelay(t=20,e=100){return Math.floor(Math.random()*(e-t+1))+t}async showCursor(){await this.page.addInitScript({content:`
|
|
@@ -36,4 +36,4 @@
|
|
|
36
36
|
(el) => {
|
|
37
37
|
el.scrollIntoView({ behavior: "auto", block: "center" });
|
|
38
38
|
}
|
|
39
|
-
`),await o.waitForTimeout(500)}catch(a){console.warn("\u7B80\u5355\u6EDA\u52A8\u4E5F\u5931\u8D25\uFF0C\u5F3A\u5236\u7EE7\u7EED:",a.message)}}return await t.clickEl(e,r)}async function Z(o,t,e,r){return await o.click(t,e,r)}var ee=require("@tocha688/utils/sync"),te=require("@tocha688/utils");async function D(o=200,t=800){let e=(0,te.rInt)(o,t);return new Promise(r=>setTimeout(r,e))}async function re(o,t="load",e=3e4){let r=t.toUpperCase();try{return console.log(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] \u76EE\u6807\u72B6\u6001: ${r}, \u8D85\u65F6: ${e/1e3}s`),await o.waitForLoadState(t,{timeout:e}),console.log(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] ${r} \u72B6\u6001\u5DF2\u5B8C\u6210\u3002`),!0}catch{return console.error(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] ${r} \u72B6\u6001\u5931\u8D25\u6216\u8D85\u65F6\u3002`),!1}}function oe(o,t,e,r={}){return new Promise(async(i,s)=>{let{frameAttachedTimeout:n=45e3,frameVisibleTimeout:c=1e4,frameBodyTimeout:a=15e3,frameInLocatorOptions:p={},waitForElementTimeout:l=15e3,timeout:u=2e3}=r;console.log(`[\u7B49\u5F85 ${String(t)} iframe \u5B8C\u5168\u52A0\u8F7D]`);try{console.log("\u7B49\u5F85 iframe \u5143\u7D20..."),await o.waitForSelector(String(t),{state:"attached",timeout:n}),console.log("\u7B49\u5F85 iframe \u53EF\u89C1..."),await o.waitForSelector(String(t),{state:"visible",timeout:c}),console.log("\u2705 iframe \u53EF\u89C1");let m=o.frameLocator(String(t));await m.locator("body").waitFor({state:"attached",timeout:a}),console.log("\u2705 iframe \u5185\u5BB9\u5DF2\u52A0\u8F7D"),console.log(`[\u7B49\u5F85\u6307\u5B9A\u5143\u7D20\u53EF\u89C1] ${String(e)}`),await m.locator(e,p).waitFor({timeout:l}),console.log("[\u7B49\u5F85\u5B8C\u5168\u52A0\u8F7D]"),await o.waitForTimeout(u),i(m)}catch(m){s(m)}})}function ie(o,t={}){return(0,ee.cancelableFunction)(async e=>{let r=Date.now();for(;e.signal.aborted===!1&&Date.now()-r<(t.timeout||3e4);){if(await o.isVisible().catch(()=>!1))return o;await D(100)}throw new Error("waitForAbort \u8D85\u65F6")})}var U=require("@tocha688/utils");async function se(o,t,e,r,i){if(typeof e=="string"&&(e=o.locator(e)),!x(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{clear:s=!0,delay:n={min:50,max:150},retries:c=3,...a}=i||{};if(await e.waitFor({state:"visible",...a}),await e.waitFor({state:"attached",...a}),await b(o,t,e,a),await D(50,100),s){let l=await e.inputValue().catch(()=>"");l&&l.length>0&&(await e.click({clickCount:3}),await D(20,50),await o.keyboard.press("Delete"),await D(20,50))}let p=R(r,5);for(let l=0;l<p.length;l++){let u=p[l];if(!await O(e)){await b(o,t,e,a);let h=await e.inputValue().catch(()=>"");h&&h.length>0&&await o.keyboard.press("End"),await D(30,60)}u&&await e.pressSequentially(u,{delay:(0,U.rInt)(n.min,n.max)}),l<p.length-1&&await D(50,150)}await D(100,200),await e.blur()}async function ne(o,t,e,r,i){if(typeof e=="string"&&(e=o.locator(e)),!x(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{clear:s=!0,delay:n={min:50,max:150},retries:c=3,...a}=i||{};if(await e.waitFor({state:"visible",...a}),await e.waitFor({state:"attached",...a}),await b(o,t,e,a),await D(50,100),s){let l=await e.inputValue().catch(()=>"");l&&l.length>0&&(await e.click({clickCount:3}),await D(20,50),await o.keyboard.press("Delete"),await D(20,50))}let p=R(r,5);for(let l=0;l<p.length;l++){let u=p[l];u&&await e.pressSequentially(u,{delay:(0,U.rInt)(n.min,n.max)}),l<p.length-1&&await D(50,150)}await D(100,200),await e.blur()}async function ae(o,t,e,r,i){if(typeof e=="string"&&(e=o.locator(e)),!x(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{retries:s=3,verify:n=!0,...c}=i||{};await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c});try{let p=await e.inputValue(),l=typeof r=="string"?r:Array.isArray(r)?r[0]?.toString():r?.toString();if(p===l)return}catch(p){console.warn(`\u83B7\u53D6\u5F53\u524D\u9009\u62E9\u503C\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await b(o,t,e,c),await D(50,100),await e.selectOption(r,c),await D(100,200),n){let p=await e.inputValue(),l=typeof r=="string"?r:Array.isArray(r)?r[0]?.toString():r?.toString();if(p!==l)throw new Error(`\u9009\u62E9\u9A8C\u8BC1\u5931\u8D25: \u671F\u671B"${l}", \u5B9E\u9645"${p}"`)}await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u9009\u62E9\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}async function ce(o,t,e,r){if(typeof e=="string"&&(e=o.locator(e)),!x(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{force:i=!1,retries:s=3,verify:n=!0,...c}=r||{};if(await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c}),!i)try{if(await e.isChecked())return}catch(p){console.warn(`\u68C0\u67E5\u52FE\u9009\u72B6\u6001\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await b(o,t,e,c),await D(50,100),await e.check({force:i,...c}),await D(100,200),n&&!await e.isChecked())throw new Error("\u52FE\u9009\u9A8C\u8BC1\u5931\u8D25: \u5143\u7D20\u672A\u88AB\u6210\u529F\u52FE\u9009");await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u52FE\u9009\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}async function le(o,t,e,r){if(typeof e=="string"&&(e=o.locator(e)),!x(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{force:i=!1,retries:s=3,verify:n=!0,...c}=r||{};if(await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c}),!i)try{if(!await e.isChecked())return}catch(p){console.warn(`\u68C0\u67E5\u52FE\u9009\u72B6\u6001\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await b(o,t,e,c),await D(50,100),await e.uncheck({force:i,...c}),await D(100,200),n&&await e.isChecked())throw new Error("\u53D6\u6D88\u52FE\u9009\u9A8C\u8BC1\u5931\u8D25: \u5143\u7D20\u4ECD\u7136\u88AB\u52FE\u9009");await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u53D6\u6D88\u52FE\u9009\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}function pe(o,t,e,r={}){let{interval:i=1e3,debug:s=!1}=r,n=[],c=!0,a=u=>{let m=u.url();(t instanceof RegExp?t.test(m):m.includes(t))&&(s&&console.log(`[Collector] \u6355\u83B7\u5230\u76EE\u6807\u8BF7\u6C42: ${m}`),n.push(u))};o.on("request",a);let p=setInterval(async()=>{if(c)for(s&&console.log(`[Poller] \u8F6E\u8BE2\u68C0\u67E5\u4E2D... \u5F53\u524D\u961F\u5217\u79EF\u538B: ${n.length}`);n.length>0;){let u=n.shift();if(u)if(e)await e(u);else{let m=`[Error] \u81F4\u547D\u9519\u8BEF: \u68C0\u6D4B\u5230\u88AB\u7981\u6B62\u7684\u8BF7\u6C42/\u672A\u5904\u7406\u7684\u8BF7\u6C42\u53D1\u9001! URL: ${u.url()}`;console.error(m),l()}}},i),l=()=>{c&&(c=!1,clearInterval(p),o.off("request",a),s&&console.log("[Poller] \u76D1\u542C\u5DF2\u505C\u6B62"))};return{stop:l}}function me(o,t,e,r={}){let{interval:i=1e3,debug:s=!1}=r,n=!0,c=!1;s&&console.log(`[ElementMonitor] \u5F00\u59CB\u76D1\u542C\u5143\u7D20: "${t}"`);let a=setInterval(async()=>{if(!(!n||c))try{if(o.isClosed()){p();return}if(await o.isVisible(t))if(s&&console.log(`[ElementMonitor] \u53D1\u73B0\u76EE\u6807\u5143\u7D20: "${t}"`),c=!0,e)try{await e(o.locator(t))}catch(u){console.error(`[Callback Error] \u5904\u7406\u5143\u7D20 "${t}" \u56DE\u8C03\u5931\u8D25:`,u)}finally{c=!1}else{let u=`[Error] \u81F4\u547D\u9519\u8BEF: \u9875\u9762\u51FA\u73B0\u4E86\u4E0D\u8BE5\u51FA\u73B0\u7684\u5143\u7D20! Selector: "${t}"`;console.error(u),p()}}catch(l){s&&console.warn("[ElementMonitor] \u8F6E\u8BE2\u68C0\u67E5\u5F02\u5E38:",l)}},i),p=()=>{n&&(n=!1,clearInterval(a),s&&console.log(`[ElementMonitor] \u505C\u6B62\u76D1\u542C\u5143\u7D20: "${t}"`))};return{stop:p}}var _=require("@tocha688/utils");async function ue(o,t,e){let r=0,i=t+(0,_.rInt)(-100,100);if(console.log(`\u5F00\u59CB\u6A21\u62DF\u6EDA\u52A8\uFF0C\u76EE\u6807\u8DDD\u79BB: ${i}px`),e){let n=await e.boundingBox();if(n){let c=n.x+n.width/2+(0,_.rInt)(-10,10),a=n.y+n.height/2+(0,_.rInt)(-10,10);await o.mouse.move(c,a)}else console.warn("Target locator provided but element is not visible/present. Falling back to global scroll.")}let s=async n=>{await o.mouse.wheel(0,n),!e&&Math.random()<.3&&await o.mouse.move((0,_.rInt)(100,500),(0,_.rInt)(100,500))};for(;r<i;){let n=(0,_.rInt)(50,150);r+n>i&&(n=i-r),await s(n),r+=n,Math.random()<.1?await(0,_.sleep)((0,_.rInt)(500,800)):await(0,_.sleep)((0,_.rInt)(30,100))}console.log("\u6EDA\u52A8\u5B8C\u6210")}var $e="_ah_",L=class o{page;mouse;constructor(t){this.page=t,this.mouse=new Q(t)}static create(t){let e=new o(t),r=Object.create(t);return Object.assign(r,t),Object.assign(r,e),["locator","getByRole","getByTestId","getByLabel","getByPlaceholder","getByText","getByAltText","getByTitle"].forEach(s=>{if(!t[s])return;let c=t[s].bind(t),a=$e+s;r[a]=c,r[s]=function(...p){let l=r[a](...p);return l&&e.enhanceLocator(l)}}),r}enhanceLocator(t){let e=Object.create(t);return Object.assign(e,t),e._loc=t,e.click=this.click.bind(this,t),e.input=e.fill=this.input.bind(this,t),e.selectOption=e.select=this.select.bind(this,t),e.check=this.check.bind(this,t),e.uncheck=this.uncheck.bind(this,t),e}async click(t,e){return b(this.page,this.mouse,t,e)}async clickPoint(t,e,r){return Z(this.mouse,t,e,r)}isLocator(t){return x(t)}async input(t,e,r){return se(this.page,this.mouse,t,e,r)}async inputFofce(t,e,r){return ne(this.page,this.mouse,t,e,r)}async select(t,e,r){return ae(this.page,this.mouse,t,e,r)}async check(t,e){return ce(this.page,this.mouse,t,e)}async uncheck(t,e){return le(this.page,this.mouse,t,e)}async rWait(t=200,e=800){return D(t,e)}async safeWaitForLoadState(t="load",e=3e4){return re(this.page,t,e)}waitForIframeComplete(t,e,r={}){return oe(this.page,t,e,r)}startRequestPolling(t,e,r={}){return pe(this.page,t,e,r)}startElementPolling(t,e,r,i={}){return me(t,e,r,i)}waitForAbort(t,e={}){return ie(t,e)}async humanScroll(t,e){return ue(this.page,t,e)}};var De=g(require("path"),1),qe=De.default.join(process.cwd(),"tmp","browser_cache");var de=g(require("path"),1),fe=require("patchright-core");function H(){let o=`${Date.now()}-${Math.random().toString(36).slice(2)}`,t=de.default.join(process.cwd(),"tmps",`brw-session-${o}`);return{sessionId:o,userDataDir:t}}async function P(o){return(await fetch(`http://127.0.0.1:${o}/json/version`).then(e=>e.json()))?.webSocketDebuggerUrl||""}async function k(o,t){let e=await o({...t}),r=await P(e.port);if(!r)throw e.close(),new Error("\u65E0\u6CD5\u83B7\u53D6\u6D4F\u89C8\u5668WebSocket URL");try{let i=await fe.chromium.connectOverCDP(r),s=i.contexts()[0]?.pages()?.[0]??await i.newPage();s.setDefaultNavigationTimeout(6e4),s.setDefaultTimeout(6e4);let n=new L(s);return i._hk_close=i.close,i.close=async function(){await i._hk_close(),await e.close()},{page:s,auto:n,brw:i}}catch(i){return console.log(i),await e.close(),await k(o,t)}}var we=require("generic-pool");var X=class{constructor(t,e,r={}){this.startFn=t;this.opts=e;this.pool=(0,we.createPool)({create:async()=>await k(this.startFn,this.opts),destroy:async i=>{await i.brw.close()},validate:async i=>i.brw.isConnected()},{min:r.min??1,max:r.max??5,testOnBorrow:r.testOnBorrow??!0,idleTimeoutMillis:r.idleTimeoutMillis??3e4})}pool;async acquire(){let t=await this.pool.acquire();return{...t,release:async()=>{await this.pool.release(t)}}}async drain(){await this.pool.drain(),await this.pool.clear()}async use(t){let e=await this.acquire();try{return await t(e)}finally{await e.release()}}};var qt=require("patchright-core"),y=g(require("fs"),1),ge=g(require("path"),1),ye=require("crypto");function he(o,t){let e=(0,ye.createHash)("md5").update(o).digest("hex"),r=ge.default.join(t,e),i=r+".meta.json";return{cacheFile:r,metaFile:i}}async function je(o,t){y.default.existsSync(t)||y.default.mkdirSync(t,{recursive:!0}),console.log("\u542F\u7528\u6D4F\u89C8\u5668\u7F13\u5B58"),await o.route("**/*",async e=>{let r=e.request();if(r.method()!=="GET")return e.continue();let i=r.resourceType();if(["xhr","fetch","websocket","document"].includes(i))return e.continue();let s=r.url(),{cacheFile:n,metaFile:c}=he(s,t);try{if(y.default.existsSync(n)&&y.default.existsSync(c)){let a=JSON.parse(y.default.readFileSync(c,"utf-8")),p=y.default.readFileSync(n);return Date.now()-a.timestamp>a.timeout?(y.default.unlinkSync(n),y.default.unlinkSync(c),e.continue()):e.fulfill({status:200,headers:a.headers,body:p,contentType:a.contentType})}}catch{}return e.continue()}),await o.on("response",async e=>{let r=e.request();if(r.method()!=="GET")return;let i=e.status();if(![200,201].includes(i))return;let s=e.url(),{cacheFile:n,metaFile:c}=he(s,t);if(y.default.existsSync(n)&&y.default.existsSync(c))return;let a=e.headers();if((a["content-type"]||"").includes("text/plain")||s.includes(";"))return;let l=a["cache-control"]||"",u=a.pragma||"";if(l.includes("no-store")||u.includes("no-cache"))return;let m=r.resourceType();if(!(!(u||l)&&(["xhr","fetch","websocket","document"].includes(m)||new URL(s).searchParams.toString().length>0)))try{let h=await e.body();y.default.writeFileSync(n,h),y.default.writeFileSync(c,JSON.stringify({url:s,headers:a,contentType:a["content-type"],timestamp:Date.now(),timeout:parseInt(a["cache-control"]?.match(/max-age=(\d+)/)?.[1]||"99999999")*1e3}))}catch{}})}async function _e(o,t,e){return await fetch(t.url(),{method:t.method(),body:t.postData(),headers:t.headers()}).then(async r=>o.fulfill({status:r.status,headers:Object.fromEntries(r.headers.entries()),body:Buffer.from(await r.arrayBuffer())})).catch(()=>o.abort())}async function ze(o){await o.route("**/*",async t=>{let e=t.request(),r=e.url(),i=e.resourceType();return["GET"].includes(e.method())?["xhr","fetch","websocket","document"].includes(i)||["script"].includes(i)&&r.includes("?")?await t.continue():await _e(t,e,o):await t.continue()})}async function Je(o){await o.route("**/*",async t=>{let e=t.request();if(e.method()!=="GET")return t.continue();let r=e.resourceType();return["xhr","fetch","websocket","document","script"].includes(r)?t.continue():t.abort()})}var xe=g(require("chrome-launcher"),1);var be=require("patchright-core");async function Ke(o){let{chromePath:t,headless:e=!1,userDataDir:r}=o,i=["--disable-blink-features=AutomationControlled","--no-sandbox","--disable-setuid-sandbox"];e&&i.push("--headless");let s=await xe.launch({chromePath:t,chromeFlags:i,userDataDir:r}),n=await P(s.port);return{userDataDir:r||"",port:s.port,browser:s,wsUrl:n,close:async()=>await s.kill(),async mainPage(){let c=await be.chromium.connectOverCDP(n),a=c.contexts()?.[0]??await c.newContext();return a?.pages()?.[0]??await a.newPage()}}}var I=g(require("fs"),1),E=g(require("path"),1),J=require("@faker-js/faker");function M(o){let t,e;t===void 0&&(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),e===void 0&&(e="hTy1bfRJz4nLPcBCO7WtmNIaGvVeul5Zo8kq32UxrYw_-0gsjp96SDFXQiEMKdHA");var r=t,i=e,s=Buffer.from(o).toString("base64").split(""),n="";return s.map((function(c){var a=r.indexOf(c);return n+=a<0?c:i.substr(a,1),c})),n}function Ae(o){let t,e;if(t===void 0&&(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),e===void 0&&(e="hTy1bfRJz4nLPcBCO7WtmNIaGvVeul5Zo8kq32UxrYw_-0gsjp96SDFXQiEMKdHA"),!o)return"";var r=t,i=e,s=o.split(""),n="";return s.map((function(c){var a=i.indexOf(c);return n+=a<0?c:r.substr(a,1),c})),Buffer.from(n,"base64").toString()}var Ie=g(require("font-list"),1),W=require("@tocha688/utils"),$=["750 \xD7 1334","800 x 600","1024 x 600","1024 x 640","1024 x 768","1152 x 864","1280 x 720","1280 x 768","1280 x 800","1280 x 960","1280 x 1024","1360 x 768","808 \xD7 1792","828 \xD7 1792","1080 x 2340","1125 x 2436","1242 x 2208","1170 \xD7 2532","1284 x 2778","1366 x 768","1400 x 1050","1400 x 900","1440 x 900","1536 x 864","1600 x 900","1600 x 1200","1680 x 1050","1920 x 1080","1920 x 1200","2048 x 1152","2304 x 1440","2560 x 1440","2560 x 1600","2880 x 1800","4096 x 2304","5120 x 2880"],q=["2","3","4","6","8","10","12","16","20","24","32","64"],Ye=["2","4","6","8","16","32","64","128"],Qe=[{name:"Google Inc. (AMD)",values:["ANGLE (AMD, RENOIR(renoir LLVM 15.0.7), OpenGL 4.6)"]},{name:"Google Inc. (Intel)",values:["ANGLE (Intel, Mesa Intel(R) Graphics (RPL-S), OpenGL 4.6)","ANGLE (Intel, Mesa Intel(R) Graphics (RPL-P), OpenGL 4.6)","ANGLE (Intel, Mesa Intel(R) Xe Graphics (TGL GT2), OpenGL 4.6)"]}],j=[{name:"Google Inc. (NVIDIA)",vendor:"nvidia",values:["ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 SUPER (0x000021C4) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6647)","ANGLE (NVIDIA, NVIDIA GeForce GTX 750 Ti (0x00001380) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6647)","ANGLE (NVIDIA, NVIDIA GeForce GTX 650 (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6140)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 Ti (0x00001C8C) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (NVIDIA, NVIDIA GeForce GT 635M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.13.6472)","ANGLE (NVIDIA, NVIDIA GeForce GT 710 (0x0000128B) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.3160)","ANGLE (NVIDIA, NVIDIA GeForce 410M (0x00001055) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6093)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1060 (0x00001C20) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5148)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 (0x00002184) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5751)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2070 SUPER (0x00001E84) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 750 Ti (0x00001380) Direct3D9Ex vs_3_0 ps_3_0, nvd3dumx.dll-26.21.14.4219)","ANGLE (NVIDIA, NVIDIA GeForce GT 730 (0x00001287) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 (0x00001F9D) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5751)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 (0x00001C91) Direct3D11 vs_5_0 ps_5_0, D3D11-22.21.13.8476)","ANGLE (NVIDIA, NVIDIA GeForce GTX 950 (0x00001402) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4187)","ANGLE (NVIDIA, NVIDIA GeForce GTX 960 (0x00001401) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce RTX 3070 (0x00002484) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6611)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5256)","ANGLE (NVIDIA, NVIDIA GeForce GTX 660 (0x000011C0) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 970 (0x000013C2) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 (0x00001F9D) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5256)","ANGLE (NVIDIA, NVIDIA GeForce 205 (0x00002504) Direct3D11 vs_4_1 ps_4_1, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1070 (0x00001BA1) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA Quadro K620 (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1060 3GB (0x00001C02) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (NVIDIA, NVIDIA GeForce GT 635M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-23.21.13.9124)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 (0x00001C91) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.3630)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4250)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 SUPER (0x00001F47) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5167)","ANGLE (NVIDIA, NVIDIA Quadro P600 (0x00001CB2) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5239)","ANGLE (NVIDIA, NVIDIA Quadro M1000M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 550 Ti (0x00001244) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce 210 (0x00000A65) Direct3D11 vs_4_0 ps_4_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 SUPER (0x00002187) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4120)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 Ti (0x00002191) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GT 1030 (0x00001D01) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 970 (0x000013C2) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1070 (0x00001BA1) Direct3D11 vs_5_0 ps_5_0, D3D11-23.21.13.8813)","ANGLE (NVIDIA, NVIDIA GeForce GT 730 (0x00001287) Direct3D11 vs_5_0 ps_5_0, D3D11-9.18.13.4411)"]},{name:"Google Inc. (AMD)",vendor:"amd",values:["ANGLE (AMD, AMD Radeon(TM) RX 560 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Mobile Graphics (0x000015DD) Direct3D9Ex vs_3_0 ps_3_0, D3D11)","ANGLE (AMD, Radeon RX RX550/550 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon R7 350 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.15029.27017)","ANGLE (AMD, AMD Radeon(TM) R7 Graphics (0x0000130F) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1034.6)","ANGLE (AMD, Radeon RX 560 Series (0x000067EF) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.15029.27017)","ANGLE (AMD, AMD Radeon HD 7800 Series (0x00006819) Direct3D9Ex vs_3_0 ps_3_0, aticfx64.dll-26.20.15029.15007)","ANGLE (AMD, AMD Radeon RX 580 2048SP (0x00006FDF) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.15003.5017)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14501.18003)","ANGLE (AMD, AMD Radeon(TM) Graphics (0x0000164E) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14044.2001)","ANGLE (AMD, AMD Radeon Series (0x00001636) Direct3D9Ex vs_3_0 ps_3_0, aticfx32.dll-23.20.15002.11)","ANGLE (AMD, Radeon (TM) RX 470 Graphics (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.13031.18002)","ANGLE (AMD, AMD Radeon HD 6530D (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, Radeon RX 580 Series (0x000067DF) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14534.2)","ANGLE (AMD, AMD Radeon(TM) RX Vega 10 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.14132.2002)","ANGLE (AMD, AMD Radeon R7 430 (0x00006611) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon (TM) R9 200 Series (0x00006811) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1034.6)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.11008.3003)","ANGLE (AMD, AMD Radeon(TM) RX Vega 10 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1028.1)","ANGLE (AMD, AMD Radeon(TM) Graphics (0x0000164E) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1020.2002)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon R7 200 Series (0x00006658) Direct3D11 vs_5_0 ps_5_0, D3D11)"]},{name:"Google Inc. (Intel)",vendor:"Intel",values:["ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.100.6617)","ANGLE (Intel, Intel(R) UHD Graphics 620 (0x00003EA0) Direct3D11 vs_5_0 ps_5_0, D3D11-24.20.100.6346)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.100.7637)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.8682)","ANGLE (Intel, Intel(R) HD Graphics Family (0x00000A16) Direct3D9Ex vs_3_0 ps_3_0, igdumdim64.dll-10.18.10.3907)","ANGLE (Intel, Intel(R) HD Graphics 4000 (0x00000162) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.4252)","ANGLE (Intel, Intel(R) HD Graphics 530 (0x0000191B) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.4364)","ANGLE (Intel, Intel(R) UHD Graphics 620 (0x00003EA0) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.9126)","ANGLE (Intel, Intel(R) UHD Graphics (0x00009BA4) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.100.7985)","ANGLE (Intel, Intel(R) HD Graphics Family (0x00000A16) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.5058)","ANGLE (Intel, Intel(R) UHD Graphics 610 (0x00003EA1) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.100.6471)","ANGLE (Intel, Intel(R) HD Graphics 4600 (0x00000416) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.14.5067)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.9466)","ANGLE (Intel, Intel(R) HD Graphics 4400 (0x0000041E) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.3412)","ANGLE (Intel, Intel(R) Iris(TM) Graphics 6100 (0x00007DD5) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (Intel, Intel(R) Iris(R) Plus Graphics (0x00008A5A) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.8853)","ANGLE (Intel, Intel(R) HD Graphics 520 (0x00001921) Direct3D11 vs_5_0 ps_5_0, D3D11-21.20.16.4727)","ANGLE (Intel, Intel(R) Iris(R) Plus Graphics (0x00008A5A) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5059)","ANGLE (Intel, Intel(R) HD Graphics 5300 (0x00007DD5) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.4531)","ANGLE (Intel, Intel(R) HD Graphics 4000 (0x00000162) Direct3D9Ex vs_3_0 ps_3_0, igdumd64.dll-9.17.10.2849)"]}];async function z(){let t=(await Ie.default.getFonts()).filter(i=>!/[\u4e00-\u9fa5]/.test(i)),e=(0,W.rInt)(5,Math.min(50,t.length)),r=[...t];for(let i=r.length-1;i>0;i--){let s=(0,W.rInt)(0,i),n=r[i];r[i]=r[s],r[s]=n}return r.slice(0,e)}var w=require("@tocha688/utils");var ve=g(require("portfinder"),1),T=g(require("fs"),1),Pe=g(require("chrome-launcher"),1),A=require("@tocha688/utils"),Le=require("patchright-core");async function G(o,t){let{userDataDir:e}=H();T.default.mkdirSync(e,{recursive:!0});let r;try{let i=await ve.default.getPortPromise({port:41e3,stopPort:49999});r=await t.prepare(e,i);let s=[`--user-data-dir=${e}`,`--remote-debugging-port=${i}`,"--remote-debugging-address=0.0.0.0",...r.args];o.headless!==!1&&!s.some(a=>a.startsWith("--headless"))&&s.push("--headless");let n=await Pe.launch({userDataDir:e,port:i,chromePath:o.chromePath,chromeFlags:s,startingUrl:r.startingUrl||"about:blank"}),c=await P(n.port);return{userDataDir:e,port:n.port,browser:n,wsUrl:c,close:async()=>{await(0,A.tryCatch)(async()=>await n.kill()),r?.cleanup&&await(0,A.tryCatch)(r.cleanup),await(0,A.tryLoop)(async()=>T.default.rmSync(e,{recursive:!0,force:!0}))},async mainPage(){let a=await Le.chromium.connectOverCDP(c),p=a.contexts()?.[0]??await a.newContext();return p?.pages()?.[0]??await p.newPage()}}}catch(i){throw await(0,A.tryLoop)(async()=>T.default.rmSync(e,{recursive:!0,force:!0})),r?.cleanup&&await(0,A.tryCatch)(r.cleanup),i}}async function Ze(o){return G(o,{prepare:async(t,e)=>{let r=E.default.join(t,"webgl.json"),i=E.default.join(t,"dynamic.config"),s=E.default.join(t,"static.config"),n=E.default.join(t,"params.config"),c,a;if(I.default.existsSync(n))c=I.default.readFileSync(n,"utf-8"),a=JSON.parse(Ae(c)).ScreenSize;else{let l={},u;o.proxy?(l=await(0,w.checkAutoProxy)(o.proxy),u=new URL(l.proxy)):l=await(0,w.getIpInfo)(l.proxy);let m={fp:(0,w.rInt)(1e5,999999),geop:l?.latitude?l?.latitude+","+l?.longitude:"",device_name:"PC"+J.faker.string.alphanumeric(8).toUpperCase(),timezone:l?.timezone||l?.timeZone||"America/Los_Angeles",proxy:{protocol:u?.protocol.replace(":","")||"http",host:u?.hostname||"127.0.0.1",port:u?.port||"8080",username:u?.username||"",password:u?.password||""},mac:J.faker.internet.mac(),scanPorts:"",screenSize:(0,w.rArrItem)($),langs:l?.languages??"en-US,en"},h=(0,w.rArrItem)(j),B={UNMASKED_VENDOR_WEBGL:h.name,UNMASKED_RENDERER_WEBGL:(0,w.rArrItem)(h.values),GPUAdapterInfo:{vendor:h.vendor,architecture:"pascal"},SUPPORTED_EXTENSIONS:[]},Se={BlockList:{Version:"1743148877",Domains:[]},StrongBlockList:{Version:"3",Domains:[]},TimeZone:m.timezone,Geoposition:m.geop},f={CookiesExportPath:"",SecurePreferenceSync:!0,PasswordExportPath:"",PasswordImportPath:"",RestoreLastSession:!0,BlockPage:"NDA0",FoceSafeBrowsing:!0,ExtensionSetting:[],DisCanvasUrl:"",MaxTouchPoints:0,MediaDevices:[{kind:"audioinput",label:"Microphone Array (Realtek(R) Audio)"},{kind:"videoinput",label:"Integrated Camera (98da:3959)"},{kind:"audiooutput",label:"Speakers (Realtek(R) Audio)"}],AudioFp:(0,w.rAutoDigitInt)(980,m.fp),WebGLMark:"5001",StartTime:Math.floor(Date.now()/1e3),GeolocationSetting:"ask",FlashPluginSetting:"block",Platform:"Win32",ScreenSize:m.screenSize,DisableBackgroundMode:!0,DisableWebRTC:!0,HardwareConcurrency:(0,w.rArrItem)(q),DeviceMemory:(0,w.rArrItem)([4,8]),LoadExtensionErrorBox:!1,ClientRectFp:(0,w.rAutoDigitInt)("5001",m.fp).toString(),ForceProcessExit:!0,ProxyUser:m.proxy.username,ProxyPassword:m.proxy.password,Langs:m.langs,AcceptLang:m.langs?m.langs+",q=0.9":"en-US,en;q=0.9",DisabledFonts:(await z()).join(",")};I.default.writeFileSync(r,JSON.stringify(B)),I.default.writeFileSync(i,M(JSON.stringify(Se))),I.default.writeFileSync(s,M(JSON.stringify(f))),c=M(JSON.stringify({UserId:"1",CanvasMark:(0,w.rAutoDigitInt)("7949",m.fp).toString(),DisableContainer:!0,WebGLFP:r,AudioFp:f.AudioFp,WebGLMark:f.WebGLMark,StartTime:f.StartTime,AllowScanPorts:m.scanPorts,GeolocationSetting:f.GeolocationSetting,FlashPluginSetting:f.FlashPluginSetting,Platform:f.Platform,ScreenSize:f.ScreenSize,DisableBackgroundMode:f.DisableBackgroundMode,DisableWebRTC:f.DisableWebRTC,HardwareConcurrency:f.HardwareConcurrency,DeviceMemory:f.DeviceMemory,LoadExtensionErrorBox:f.LoadExtensionErrorBox,ClientRectFp:f.ClientRectFp,CanvasMarkEx:(0,w.rAutoDigitInt)("7949",m.fp).toString(),WebGLMarkEx:(0,w.rAutoDigitInt)("5001",m.fp).toString(),command_line:{"do-not-de-elevate":""},ProxyChain:[{scheme:m.proxy.protocol,host:m.proxy.host,port:m.proxy.port,account:m.proxy.username,password:m.proxy.password}],ForceProcessExit:f.ForceProcessExit,ProxyUser:f.ProxyUser,ProxyPassword:f.ProxyPassword,Langs:f.Langs,AcceptLang:f.AcceptLang,TimeZone:m.timezone,Geoposition:m.geop,DynamicConfig:i,StaticConfig:s})),I.default.writeFileSync(n,c),a=f.ScreenSize}return{args:["--disable-background-networking","--disable-client-side-phishing-detection","--disable-default-apps","--disable-hang-monitor","--disable-popup-blocking","--disable-prompt-on-repost","--disable-sync","--metrics-recording-only","--no-first-run","--safebrowsing-disable-auto-update","--password-store=basic","--no-service-autorun","--disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes","--force-color-profile=srgb","--use-mock-keychain","--export-tagged-pdf","--no-default-browser-check","--window-position=0,0","--disable-background-mode","--ash-host-window-bounds="+a,"--window-size="+a,"--disable-renderer-accessibility","--disable-legacy-window","--fake-variations-channel=stable","--variations-server-url=https://clientservices.googleapis.com/chrome-variations/seed","--component-updater=initial-delay=6e5","--lang=en-US","--enable-features=NetworkService,NetworkServiceInProcess,LoadCryptoTokenExtension,PermuteTLSExtensions","--enable-blink-features=IdleDetection,Fledge","--extended-parameters="+c,"--flag-switches-begin","--flag-switches-end","--load-extension=","--no-sandbox"],startingUrl:"https://ipapi.co/json/"}}})}var Ge=require("@faker-js/faker"),C=require("@tocha688/utils");var V=g(require("fs"),1),Ee=g(require("path"),1);async function Ne(o){return G(o,{prepare:async(t,e)=>{let r;o.proxy&&(r=await(0,C.startProxyServer)(o.proxy),console.log(`Started proxy server on port ${r.port}`));let i=r?.ipinfo;i&&(i=await(0,C.getIpInfo)(i.proxy));let s=Ee.default.join(t,"fingerprint.config"),n;V.default.existsSync(s)?n=V.default.readFileSync(s,"utf-8"):(n=Ge.faker.number.int({min:1e7,max:99999999}).toString(),V.default.writeFileSync(s,n));let c=["--allow-pre-commit-input","--disable-background-networking","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad","--disable-client-side-phishing-detection","--disable-component-extensions-with-background-pages","--disable-crash-reporter","--disable-default-apps","--disable-dev-shm-usage","--disable-hang-monitor","--disable-infobars","--disable-ipc-flooding-protection","--disable-popup-blocking","--disable-prompt-on-repost","--disable-renderer-backgrounding","--disable-search-engine-choice-screen","--disable-sync","--export-tagged-pdf","--force-color-profile=srgb","--generate-pdf-document-outline","--metrics-recording-only","--no-first-run","--password-store=basic","--use-mock-keychain","--disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes","--enable-features=PdfOopif","--fingerprints="+n,"--window-size=1280,720","--window-position=0,0","--no-sandbox","--ignore-certificate-errors","--notice-number=1","--ignores=tls","--enable-logging","--timezone="+(i?.timezone??"America/Los_Angeles"),"--lang=en-US"];return r&&r.port&&c.push(`--proxy-server=http://127.0.0.1:${r.port}`),{args:c,startingUrl:"https://ipapi.co/json/",cleanup:async()=>{r&&await r.server.close(!0)}}}})}async function et(o){return Ne(o)}var br=require("chrome-launcher"),Ar=require("proxy-chain");0&&(module.exports={AdsBrowserStartMain,AutoHelper,BrowserCachePath,BrowserPool,Cpus,HumanMouse,LinuxWebGL,Memorys,OKBrowserCreate,OKBrowserStartMain,PcScreen,WindowsWebGL,createBrowser,fetchResource,getBrowserWebSocketUrl,isElementFocused,isLocator,launchBrowserBase,makeUniqueBrowserConfig,rSysFonts,routeAssetsAbort,routeAssetsCache,routeAssetsLocal,splitTextIntoChunks,startLocalBrowser});
|
|
39
|
+
`),await o.waitForTimeout(500)}catch(a){console.warn("\u7B80\u5355\u6EDA\u52A8\u4E5F\u5931\u8D25\uFF0C\u5F3A\u5236\u7EE7\u7EED:",a.message)}}return await t.clickEl(e,r)}async function Z(o,t,e,r){return await o.click(t,e,r)}var ee=require("@tocha688/utils/sync"),te=require("@tocha688/utils");async function D(o=200,t=800){let e=(0,te.rInt)(o,t);return new Promise(r=>setTimeout(r,e))}async function re(o,t="load",e=3e4){let r=t.toUpperCase();try{return console.log(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] \u76EE\u6807\u72B6\u6001: ${r}, \u8D85\u65F6: ${e/1e3}s`),await o.waitForLoadState(t,{timeout:e}),console.log(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] ${r} \u72B6\u6001\u5DF2\u5B8C\u6210\u3002`),!0}catch{return console.error(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] ${r} \u72B6\u6001\u5931\u8D25\u6216\u8D85\u65F6\u3002`),!1}}function oe(o,t,e,r={}){return new Promise(async(i,s)=>{let{frameAttachedTimeout:n=45e3,frameVisibleTimeout:c=1e4,frameBodyTimeout:a=15e3,frameInLocatorOptions:p={},waitForElementTimeout:l=15e3,timeout:u=2e3}=r;console.log(`[\u7B49\u5F85 ${String(t)} iframe \u5B8C\u5168\u52A0\u8F7D]`);try{console.log("\u7B49\u5F85 iframe \u5143\u7D20..."),await o.waitForSelector(String(t),{state:"attached",timeout:n}),console.log("\u7B49\u5F85 iframe \u53EF\u89C1..."),await o.waitForSelector(String(t),{state:"visible",timeout:c}),console.log("\u2705 iframe \u53EF\u89C1");let m=o.frameLocator(String(t));await m.locator("body").waitFor({state:"attached",timeout:a}),console.log("\u2705 iframe \u5185\u5BB9\u5DF2\u52A0\u8F7D"),console.log(`[\u7B49\u5F85\u6307\u5B9A\u5143\u7D20\u53EF\u89C1] ${String(e)}`),await m.locator(e,p).waitFor({timeout:l}),console.log("[\u7B49\u5F85\u5B8C\u5168\u52A0\u8F7D]"),await o.waitForTimeout(u),i(m)}catch(m){s(m)}})}function ie(o,t={}){return(0,ee.cancelableFunction)(async e=>{let r=Date.now();for(;e.signal.aborted===!1&&Date.now()-r<(t.timeout||3e4);){if(await o.isVisible().catch(()=>!1))return o;await D(100)}throw new Error("waitForAbort \u8D85\u65F6")})}var U=require("@tocha688/utils");async function se(o,t,e,r,i){if(typeof e=="string"&&(e=o.locator(e)),!x(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{clear:s=!0,delay:n={min:50,max:150},retries:c=3,...a}=i||{};if(await e.waitFor({state:"visible",...a}),await e.waitFor({state:"attached",...a}),await b(o,t,e,a),await D(50,100),s){let l=await e.inputValue().catch(()=>"");l&&l.length>0&&(await e.click({clickCount:3}),await D(20,50),await o.keyboard.press("Delete"),await D(20,50))}let p=R(r,5);for(let l=0;l<p.length;l++){let u=p[l];if(!await O(e)){await b(o,t,e,a);let h=await e.inputValue().catch(()=>"");h&&h.length>0&&await o.keyboard.press("End"),await D(30,60)}u&&await e.pressSequentially(u,{delay:(0,U.rInt)(n.min,n.max)}),l<p.length-1&&await D(50,150)}await D(100,200),await e.blur()}async function ne(o,t,e,r,i){if(typeof e=="string"&&(e=o.locator(e)),!x(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{clear:s=!0,delay:n={min:50,max:150},retries:c=3,...a}=i||{};if(await e.waitFor({state:"visible",...a}),await e.waitFor({state:"attached",...a}),await b(o,t,e,a),await D(50,100),s){let l=await e.inputValue().catch(()=>"");l&&l.length>0&&(await e.click({clickCount:3}),await D(20,50),await o.keyboard.press("Delete"),await D(20,50))}let p=R(r,5);for(let l=0;l<p.length;l++){let u=p[l];u&&await e.pressSequentially(u,{delay:(0,U.rInt)(n.min,n.max)}),l<p.length-1&&await D(50,150)}await D(100,200),await e.blur()}async function ae(o,t,e,r,i){if(typeof e=="string"&&(e=o.locator(e)),!x(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{retries:s=3,verify:n=!0,...c}=i||{};await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c});try{let p=await e.inputValue(),l=typeof r=="string"?r:Array.isArray(r)?r[0]?.toString():r?.toString();if(p===l)return}catch(p){console.warn(`\u83B7\u53D6\u5F53\u524D\u9009\u62E9\u503C\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await b(o,t,e,c),await D(50,100),await e.selectOption(r,c),await D(100,200),n){let p=await e.inputValue(),l=typeof r=="string"?r:Array.isArray(r)?r[0]?.toString():r?.toString();if(p!==l)throw new Error(`\u9009\u62E9\u9A8C\u8BC1\u5931\u8D25: \u671F\u671B"${l}", \u5B9E\u9645"${p}"`)}await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u9009\u62E9\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}async function ce(o,t,e,r){if(typeof e=="string"&&(e=o.locator(e)),!x(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{force:i=!1,retries:s=3,verify:n=!0,...c}=r||{};if(await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c}),!i)try{if(await e.isChecked())return}catch(p){console.warn(`\u68C0\u67E5\u52FE\u9009\u72B6\u6001\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await b(o,t,e,c),await D(50,100),await e.check({force:i,...c}),await D(100,200),n&&!await e.isChecked())throw new Error("\u52FE\u9009\u9A8C\u8BC1\u5931\u8D25: \u5143\u7D20\u672A\u88AB\u6210\u529F\u52FE\u9009");await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u52FE\u9009\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}async function le(o,t,e,r){if(typeof e=="string"&&(e=o.locator(e)),!x(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{force:i=!1,retries:s=3,verify:n=!0,...c}=r||{};if(await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c}),!i)try{if(!await e.isChecked())return}catch(p){console.warn(`\u68C0\u67E5\u52FE\u9009\u72B6\u6001\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await b(o,t,e,c),await D(50,100),await e.uncheck({force:i,...c}),await D(100,200),n&&await e.isChecked())throw new Error("\u53D6\u6D88\u52FE\u9009\u9A8C\u8BC1\u5931\u8D25: \u5143\u7D20\u4ECD\u7136\u88AB\u52FE\u9009");await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u53D6\u6D88\u52FE\u9009\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}function pe(o,t,e,r={}){let{interval:i=1e3,debug:s=!1}=r,n=[],c=!0,a=u=>{let m=u.url();(t instanceof RegExp?t.test(m):m.includes(t))&&(s&&console.log(`[Collector] \u6355\u83B7\u5230\u76EE\u6807\u8BF7\u6C42: ${m}`),n.push(u))};o.on("request",a);let p=setInterval(async()=>{if(c)for(s&&console.log(`[Poller] \u8F6E\u8BE2\u68C0\u67E5\u4E2D... \u5F53\u524D\u961F\u5217\u79EF\u538B: ${n.length}`);n.length>0;){let u=n.shift();if(u)if(e)await e(u);else{let m=`[Error] \u81F4\u547D\u9519\u8BEF: \u68C0\u6D4B\u5230\u88AB\u7981\u6B62\u7684\u8BF7\u6C42/\u672A\u5904\u7406\u7684\u8BF7\u6C42\u53D1\u9001! URL: ${u.url()}`;console.error(m),l()}}},i),l=()=>{c&&(c=!1,clearInterval(p),o.off("request",a),s&&console.log("[Poller] \u76D1\u542C\u5DF2\u505C\u6B62"))};return{stop:l}}function me(o,t,e,r={}){let{interval:i=1e3,debug:s=!1}=r,n=!0,c=!1;s&&console.log(`[ElementMonitor] \u5F00\u59CB\u76D1\u542C\u5143\u7D20: "${t}"`);let a=setInterval(async()=>{if(!(!n||c))try{if(o.isClosed()){p();return}if(await o.isVisible(t))if(s&&console.log(`[ElementMonitor] \u53D1\u73B0\u76EE\u6807\u5143\u7D20: "${t}"`),c=!0,e)try{await e(o.locator(t))}catch(u){console.error(`[Callback Error] \u5904\u7406\u5143\u7D20 "${t}" \u56DE\u8C03\u5931\u8D25:`,u)}finally{c=!1}else{let u=`[Error] \u81F4\u547D\u9519\u8BEF: \u9875\u9762\u51FA\u73B0\u4E86\u4E0D\u8BE5\u51FA\u73B0\u7684\u5143\u7D20! Selector: "${t}"`;console.error(u),p()}}catch(l){s&&console.warn("[ElementMonitor] \u8F6E\u8BE2\u68C0\u67E5\u5F02\u5E38:",l)}},i),p=()=>{n&&(n=!1,clearInterval(a),s&&console.log(`[ElementMonitor] \u505C\u6B62\u76D1\u542C\u5143\u7D20: "${t}"`))};return{stop:p}}var _=require("@tocha688/utils");async function ue(o,t,e){let r=0,i=t+(0,_.rInt)(-100,100);if(console.log(`\u5F00\u59CB\u6A21\u62DF\u6EDA\u52A8\uFF0C\u76EE\u6807\u8DDD\u79BB: ${i}px`),e){let n=await e.boundingBox();if(n){let c=n.x+n.width/2+(0,_.rInt)(-10,10),a=n.y+n.height/2+(0,_.rInt)(-10,10);await o.mouse.move(c,a)}else console.warn("Target locator provided but element is not visible/present. Falling back to global scroll.")}let s=async n=>{await o.mouse.wheel(0,n),!e&&Math.random()<.3&&await o.mouse.move((0,_.rInt)(100,500),(0,_.rInt)(100,500))};for(;r<i;){let n=(0,_.rInt)(50,150);r+n>i&&(n=i-r),await s(n),r+=n,Math.random()<.1?await(0,_.sleep)((0,_.rInt)(500,800)):await(0,_.sleep)((0,_.rInt)(30,100))}console.log("\u6EDA\u52A8\u5B8C\u6210")}var qe="_ah_",L=class o{page;mouse;constructor(t){this.page=t,this.mouse=new Q(t)}static create(t){let e=new o(t),r=Object.create(t);return Object.assign(r,t),Object.assign(r,e),["locator","getByRole","getByTestId","getByLabel","getByPlaceholder","getByText","getByAltText","getByTitle"].forEach(s=>{if(!t[s])return;let c=t[s].bind(t),a=qe+s;r[a]=c,r[s]=function(...p){let l=r[a](...p);return l&&e.enhanceLocator(l)}}),r}enhanceLocator(t){let e=Object.create(t);return Object.assign(e,t),e._loc=t,e.click=this.click.bind(this,t),e.input=e.fill=this.input.bind(this,t),e.selectOption=e.select=this.select.bind(this,t),e.check=this.check.bind(this,t),e.uncheck=this.uncheck.bind(this,t),e}async click(t,e){return b(this.page,this.mouse,t,e)}async clickPoint(t,e,r){return Z(this.mouse,t,e,r)}isLocator(t){return x(t)}async input(t,e,r){return se(this.page,this.mouse,t,e,r)}async inputFofce(t,e,r){return ne(this.page,this.mouse,t,e,r)}async select(t,e,r){return ae(this.page,this.mouse,t,e,r)}async check(t,e){return ce(this.page,this.mouse,t,e)}async uncheck(t,e){return le(this.page,this.mouse,t,e)}async rWait(t=200,e=800){return D(t,e)}async safeWaitForLoadState(t="load",e=3e4){return re(this.page,t,e)}waitForIframeComplete(t,e,r={}){return oe(this.page,t,e,r)}startRequestPolling(t,e,r={}){return pe(this.page,t,e,r)}startElementPolling(t,e,r,i={}){return me(t,e,r,i)}waitForAbort(t,e={}){return ie(t,e)}async humanScroll(t,e){return ue(this.page,t,e)}};var De=g(require("path"),1),je=De.default.join(process.cwd(),"tmp","browser_cache");var de=g(require("path"),1),fe=require("patchright-core");function H(){let o=`${Date.now()}-${Math.random().toString(36).slice(2)}`,t=de.default.join(process.cwd(),"tmps",`brw-session-${o}`);return{sessionId:o,userDataDir:t}}async function P(o){return(await fetch(`http://127.0.0.1:${o}/json/version`).then(e=>e.json()))?.webSocketDebuggerUrl||""}async function k(o,t){let e=await o({...t}),r=await P(e.port);if(!r)throw e.close(),new Error("\u65E0\u6CD5\u83B7\u53D6\u6D4F\u89C8\u5668WebSocket URL");try{let i=await fe.chromium.connectOverCDP(r),s=i.contexts()[0]?.pages()?.[0]??await i.newPage();s.setDefaultNavigationTimeout(6e4),s.setDefaultTimeout(6e4);let n=new L(s);return i._hk_close=i.close,i.close=async function(){await i._hk_close(),await e.close()},{page:s,auto:n,brw:i}}catch(i){return console.log(i),await e.close(),await k(o,t)}}var we=require("generic-pool");var X=class{constructor(t,e,r={}){this.startFn=t;this.opts=e;this.pool=(0,we.createPool)({create:async()=>await k(this.startFn,this.opts),destroy:async i=>{await i.brw.close()},validate:async i=>i.brw.isConnected()},{min:r.min??1,max:r.max??5,testOnBorrow:r.testOnBorrow??!0,idleTimeoutMillis:r.idleTimeoutMillis??3e4})}pool;async acquire(){let t=await this.pool.acquire();return{...t,release:async()=>{await this.pool.release(t)}}}async drain(){await this.pool.drain(),await this.pool.clear()}async use(t){let e=await this.acquire();try{return await t(e)}finally{await e.release()}}};var jt=require("patchright-core"),y=g(require("fs"),1),ge=g(require("path"),1),ye=require("crypto");var _e=require("@tocha688/utils");function he(o,t){let e=(0,ye.createHash)("md5").update(o).digest("hex"),r=ge.default.join(t,e),i=r+".meta.json";return{cacheFile:r,metaFile:i}}async function ze(o,t=(0,_e.getAbsolutePath)("./tmps/browser_cache")){y.default.existsSync(t)||y.default.mkdirSync(t,{recursive:!0}),console.log("\u542F\u7528\u6D4F\u89C8\u5668\u7F13\u5B58"),await o.route("**/*",async e=>{let r=e.request();if(r.method()!=="GET")return e.continue();let i=r.resourceType();if(["xhr","fetch","websocket","document"].includes(i))return e.continue();let s=r.url(),{cacheFile:n,metaFile:c}=he(s,t);try{if(y.default.existsSync(n)&&y.default.existsSync(c)){let a=JSON.parse(y.default.readFileSync(c,"utf-8")),p=y.default.readFileSync(n);return Date.now()-a.timestamp>a.timeout?(y.default.unlinkSync(n),y.default.unlinkSync(c),e.continue()):e.fulfill({status:200,headers:a.headers,body:p,contentType:a.contentType})}}catch{}return e.continue()}),await o.on("response",async e=>{let r=e.request();if(r.method()!=="GET")return;let i=e.status();if(![200,201].includes(i))return;let s=e.url(),{cacheFile:n,metaFile:c}=he(s,t);if(y.default.existsSync(n)&&y.default.existsSync(c))return;let a=e.headers();if((a["content-type"]||"").includes("text/plain")||s.includes(";"))return;let l=a["cache-control"]||"",u=a.pragma||"";if(l.includes("no-store")||u.includes("no-cache"))return;let m=r.resourceType();if(!(!(u||l)&&(["xhr","fetch","websocket","document"].includes(m)||new URL(s).searchParams.toString().length>0)))try{let h=await e.body();y.default.writeFileSync(n,h),y.default.writeFileSync(c,JSON.stringify({url:s,headers:a,contentType:a["content-type"],timestamp:Date.now(),timeout:parseInt(a["cache-control"]?.match(/max-age=(\d+)/)?.[1]||"99999999")*1e3}))}catch{}})}async function xe(o,t,e){return await fetch(t.url(),{method:t.method(),body:t.postData(),headers:t.headers()}).then(async r=>o.fulfill({status:r.status,headers:Object.fromEntries(r.headers.entries()),body:Buffer.from(await r.arrayBuffer())})).catch(()=>o.abort())}async function Je(o){await o.route("**/*",async t=>{let e=t.request(),r=e.url(),i=e.resourceType();return["GET"].includes(e.method())?["xhr","fetch","websocket","document"].includes(i)||["script"].includes(i)&&r.includes("?")?await t.continue():await xe(t,e,o):await t.continue()})}async function Ke(o){await o.route("**/*",async t=>{let e=t.request();if(e.method()!=="GET")return t.continue();let r=e.resourceType();return["xhr","fetch","websocket","document","script"].includes(r)?t.continue():t.abort()})}var be=g(require("chrome-launcher"),1);var Ae=require("patchright-core");async function Ye(o){let{chromePath:t,headless:e=!1,userDataDir:r}=o,i=["--disable-blink-features=AutomationControlled","--no-sandbox","--disable-setuid-sandbox"];e&&i.push("--headless");let s=await be.launch({chromePath:t,chromeFlags:i,userDataDir:r}),n=await P(s.port);return{userDataDir:r||"",port:s.port,browser:s,wsUrl:n,close:async()=>await s.kill(),async mainPage(){let c=await Ae.chromium.connectOverCDP(n),a=c.contexts()?.[0]??await c.newContext();return a?.pages()?.[0]??await a.newPage()}}}var I=g(require("fs"),1),E=g(require("path"),1),J=require("@faker-js/faker");function M(o){let t,e;t===void 0&&(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),e===void 0&&(e="hTy1bfRJz4nLPcBCO7WtmNIaGvVeul5Zo8kq32UxrYw_-0gsjp96SDFXQiEMKdHA");var r=t,i=e,s=Buffer.from(o).toString("base64").split(""),n="";return s.map((function(c){var a=r.indexOf(c);return n+=a<0?c:i.substr(a,1),c})),n}function Ie(o){let t,e;if(t===void 0&&(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),e===void 0&&(e="hTy1bfRJz4nLPcBCO7WtmNIaGvVeul5Zo8kq32UxrYw_-0gsjp96SDFXQiEMKdHA"),!o)return"";var r=t,i=e,s=o.split(""),n="";return s.map((function(c){var a=i.indexOf(c);return n+=a<0?c:r.substr(a,1),c})),Buffer.from(n,"base64").toString()}var ve=g(require("font-list"),1),W=require("@tocha688/utils"),$=["750 \xD7 1334","800 x 600","1024 x 600","1024 x 640","1024 x 768","1152 x 864","1280 x 720","1280 x 768","1280 x 800","1280 x 960","1280 x 1024","1360 x 768","808 \xD7 1792","828 \xD7 1792","1080 x 2340","1125 x 2436","1242 x 2208","1170 \xD7 2532","1284 x 2778","1366 x 768","1400 x 1050","1400 x 900","1440 x 900","1536 x 864","1600 x 900","1600 x 1200","1680 x 1050","1920 x 1080","1920 x 1200","2048 x 1152","2304 x 1440","2560 x 1440","2560 x 1600","2880 x 1800","4096 x 2304","5120 x 2880"],q=["2","3","4","6","8","10","12","16","20","24","32","64"],Qe=["2","4","6","8","16","32","64","128"],Ze=[{name:"Google Inc. (AMD)",values:["ANGLE (AMD, RENOIR(renoir LLVM 15.0.7), OpenGL 4.6)"]},{name:"Google Inc. (Intel)",values:["ANGLE (Intel, Mesa Intel(R) Graphics (RPL-S), OpenGL 4.6)","ANGLE (Intel, Mesa Intel(R) Graphics (RPL-P), OpenGL 4.6)","ANGLE (Intel, Mesa Intel(R) Xe Graphics (TGL GT2), OpenGL 4.6)"]}],j=[{name:"Google Inc. (NVIDIA)",vendor:"nvidia",values:["ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 SUPER (0x000021C4) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6647)","ANGLE (NVIDIA, NVIDIA GeForce GTX 750 Ti (0x00001380) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6647)","ANGLE (NVIDIA, NVIDIA GeForce GTX 650 (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6140)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 Ti (0x00001C8C) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (NVIDIA, NVIDIA GeForce GT 635M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.13.6472)","ANGLE (NVIDIA, NVIDIA GeForce GT 710 (0x0000128B) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.3160)","ANGLE (NVIDIA, NVIDIA GeForce 410M (0x00001055) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6093)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1060 (0x00001C20) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5148)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 (0x00002184) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5751)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2070 SUPER (0x00001E84) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 750 Ti (0x00001380) Direct3D9Ex vs_3_0 ps_3_0, nvd3dumx.dll-26.21.14.4219)","ANGLE (NVIDIA, NVIDIA GeForce GT 730 (0x00001287) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 (0x00001F9D) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5751)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 (0x00001C91) Direct3D11 vs_5_0 ps_5_0, D3D11-22.21.13.8476)","ANGLE (NVIDIA, NVIDIA GeForce GTX 950 (0x00001402) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4187)","ANGLE (NVIDIA, NVIDIA GeForce GTX 960 (0x00001401) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce RTX 3070 (0x00002484) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6611)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5256)","ANGLE (NVIDIA, NVIDIA GeForce GTX 660 (0x000011C0) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 970 (0x000013C2) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 (0x00001F9D) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5256)","ANGLE (NVIDIA, NVIDIA GeForce 205 (0x00002504) Direct3D11 vs_4_1 ps_4_1, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1070 (0x00001BA1) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA Quadro K620 (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1060 3GB (0x00001C02) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (NVIDIA, NVIDIA GeForce GT 635M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-23.21.13.9124)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 (0x00001C91) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.3630)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4250)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 SUPER (0x00001F47) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5167)","ANGLE (NVIDIA, NVIDIA Quadro P600 (0x00001CB2) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5239)","ANGLE (NVIDIA, NVIDIA Quadro M1000M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 550 Ti (0x00001244) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce 210 (0x00000A65) Direct3D11 vs_4_0 ps_4_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 SUPER (0x00002187) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4120)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 Ti (0x00002191) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GT 1030 (0x00001D01) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 970 (0x000013C2) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1070 (0x00001BA1) Direct3D11 vs_5_0 ps_5_0, D3D11-23.21.13.8813)","ANGLE (NVIDIA, NVIDIA GeForce GT 730 (0x00001287) Direct3D11 vs_5_0 ps_5_0, D3D11-9.18.13.4411)"]},{name:"Google Inc. (AMD)",vendor:"amd",values:["ANGLE (AMD, AMD Radeon(TM) RX 560 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Mobile Graphics (0x000015DD) Direct3D9Ex vs_3_0 ps_3_0, D3D11)","ANGLE (AMD, Radeon RX RX550/550 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon R7 350 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.15029.27017)","ANGLE (AMD, AMD Radeon(TM) R7 Graphics (0x0000130F) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1034.6)","ANGLE (AMD, Radeon RX 560 Series (0x000067EF) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.15029.27017)","ANGLE (AMD, AMD Radeon HD 7800 Series (0x00006819) Direct3D9Ex vs_3_0 ps_3_0, aticfx64.dll-26.20.15029.15007)","ANGLE (AMD, AMD Radeon RX 580 2048SP (0x00006FDF) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.15003.5017)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14501.18003)","ANGLE (AMD, AMD Radeon(TM) Graphics (0x0000164E) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14044.2001)","ANGLE (AMD, AMD Radeon Series (0x00001636) Direct3D9Ex vs_3_0 ps_3_0, aticfx32.dll-23.20.15002.11)","ANGLE (AMD, Radeon (TM) RX 470 Graphics (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.13031.18002)","ANGLE (AMD, AMD Radeon HD 6530D (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, Radeon RX 580 Series (0x000067DF) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14534.2)","ANGLE (AMD, AMD Radeon(TM) RX Vega 10 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.14132.2002)","ANGLE (AMD, AMD Radeon R7 430 (0x00006611) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon (TM) R9 200 Series (0x00006811) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1034.6)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.11008.3003)","ANGLE (AMD, AMD Radeon(TM) RX Vega 10 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1028.1)","ANGLE (AMD, AMD Radeon(TM) Graphics (0x0000164E) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1020.2002)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon R7 200 Series (0x00006658) Direct3D11 vs_5_0 ps_5_0, D3D11)"]},{name:"Google Inc. (Intel)",vendor:"Intel",values:["ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.100.6617)","ANGLE (Intel, Intel(R) UHD Graphics 620 (0x00003EA0) Direct3D11 vs_5_0 ps_5_0, D3D11-24.20.100.6346)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.100.7637)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.8682)","ANGLE (Intel, Intel(R) HD Graphics Family (0x00000A16) Direct3D9Ex vs_3_0 ps_3_0, igdumdim64.dll-10.18.10.3907)","ANGLE (Intel, Intel(R) HD Graphics 4000 (0x00000162) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.4252)","ANGLE (Intel, Intel(R) HD Graphics 530 (0x0000191B) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.4364)","ANGLE (Intel, Intel(R) UHD Graphics 620 (0x00003EA0) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.9126)","ANGLE (Intel, Intel(R) UHD Graphics (0x00009BA4) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.100.7985)","ANGLE (Intel, Intel(R) HD Graphics Family (0x00000A16) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.5058)","ANGLE (Intel, Intel(R) UHD Graphics 610 (0x00003EA1) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.100.6471)","ANGLE (Intel, Intel(R) HD Graphics 4600 (0x00000416) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.14.5067)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.9466)","ANGLE (Intel, Intel(R) HD Graphics 4400 (0x0000041E) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.3412)","ANGLE (Intel, Intel(R) Iris(TM) Graphics 6100 (0x00007DD5) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (Intel, Intel(R) Iris(R) Plus Graphics (0x00008A5A) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.8853)","ANGLE (Intel, Intel(R) HD Graphics 520 (0x00001921) Direct3D11 vs_5_0 ps_5_0, D3D11-21.20.16.4727)","ANGLE (Intel, Intel(R) Iris(R) Plus Graphics (0x00008A5A) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5059)","ANGLE (Intel, Intel(R) HD Graphics 5300 (0x00007DD5) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.4531)","ANGLE (Intel, Intel(R) HD Graphics 4000 (0x00000162) Direct3D9Ex vs_3_0 ps_3_0, igdumd64.dll-9.17.10.2849)"]}];async function z(){let t=(await ve.default.getFonts()).filter(i=>!/[\u4e00-\u9fa5]/.test(i)),e=(0,W.rInt)(5,Math.min(50,t.length)),r=[...t];for(let i=r.length-1;i>0;i--){let s=(0,W.rInt)(0,i),n=r[i];r[i]=r[s],r[s]=n}return r.slice(0,e)}var w=require("@tocha688/utils");var Pe=g(require("portfinder"),1),T=g(require("fs"),1),Le=g(require("chrome-launcher"),1),A=require("@tocha688/utils"),Ge=require("patchright-core");async function G(o,t){o.userDataDir=o.userDataDir||H().userDataDir;let{userDataDir:e}=o;T.default.mkdirSync(e,{recursive:!0});let r;try{let i=await Pe.default.getPortPromise({port:41e3,stopPort:49999});r=await t.prepare(e,i);let s=[`--user-data-dir=${e}`,`--remote-debugging-port=${i}`,"--remote-debugging-address=0.0.0.0",...r.args];o.headless!==!1&&!s.some(a=>a.startsWith("--headless"))&&s.push("--headless");let n=await Le.launch({userDataDir:e,port:i,chromePath:o.chromePath,chromeFlags:s,startingUrl:r.startingUrl||"about:blank"}),c=await P(n.port);return{userDataDir:e,port:n.port,browser:n,wsUrl:c,close:async()=>{await(0,A.tryCatch)(async()=>await n.kill()),r?.cleanup&&await(0,A.tryCatch)(r.cleanup),await(0,A.tryLoop)(async()=>T.default.rmSync(e,{recursive:!0,force:!0}))},async mainPage(){let a=await Ge.chromium.connectOverCDP(c),p=a.contexts()?.[0]??await a.newContext();return p?.pages()?.[0]??await p.newPage()}}}catch(i){throw await(0,A.tryLoop)(async()=>T.default.rmSync(e,{recursive:!0,force:!0})),r?.cleanup&&await(0,A.tryCatch)(r.cleanup),i}}async function et(o){return G(o,{prepare:async(t,e)=>{let r=E.default.join(t,"webgl.json"),i=E.default.join(t,"dynamic.config"),s=E.default.join(t,"static.config"),n=E.default.join(t,"params.config"),c,a;if(I.default.existsSync(n))c=I.default.readFileSync(n,"utf-8"),a=JSON.parse(Ie(c)).ScreenSize;else{let l={},u;o.proxy?(l=await(0,w.checkAutoProxy)(o.proxy),u=new URL(l.proxy)):l=await(0,w.getIpInfo)(l.proxy);let m={fp:(0,w.rInt)(1e5,999999),geop:l?.latitude?l?.latitude+","+l?.longitude:"",device_name:"PC"+J.faker.string.alphanumeric(8).toUpperCase(),timezone:l?.timezone||l?.timeZone||"America/Los_Angeles",proxy:{protocol:u?.protocol.replace(":","")||"http",host:u?.hostname||"127.0.0.1",port:u?.port||"8080",username:u?.username||"",password:u?.password||""},mac:J.faker.internet.mac(),scanPorts:"",screenSize:(0,w.rArrItem)($),langs:l?.languages??"en-US,en"},h=(0,w.rArrItem)(j),B={UNMASKED_VENDOR_WEBGL:h.name,UNMASKED_RENDERER_WEBGL:(0,w.rArrItem)(h.values),GPUAdapterInfo:{vendor:h.vendor,architecture:"pascal"},SUPPORTED_EXTENSIONS:[]},Fe={BlockList:{Version:"1743148877",Domains:[]},StrongBlockList:{Version:"3",Domains:[]},TimeZone:m.timezone,Geoposition:m.geop},f={CookiesExportPath:"",SecurePreferenceSync:!0,PasswordExportPath:"",PasswordImportPath:"",RestoreLastSession:!0,BlockPage:"NDA0",FoceSafeBrowsing:!0,ExtensionSetting:[],DisCanvasUrl:"",MaxTouchPoints:0,MediaDevices:[{kind:"audioinput",label:"Microphone Array (Realtek(R) Audio)"},{kind:"videoinput",label:"Integrated Camera (98da:3959)"},{kind:"audiooutput",label:"Speakers (Realtek(R) Audio)"}],AudioFp:(0,w.rAutoDigitInt)(980,m.fp),WebGLMark:"5001",StartTime:Math.floor(Date.now()/1e3),GeolocationSetting:"ask",FlashPluginSetting:"block",Platform:"Win32",ScreenSize:m.screenSize,DisableBackgroundMode:!0,DisableWebRTC:!0,HardwareConcurrency:(0,w.rArrItem)(q),DeviceMemory:(0,w.rArrItem)([4,8]),LoadExtensionErrorBox:!1,ClientRectFp:(0,w.rAutoDigitInt)("5001",m.fp).toString(),ForceProcessExit:!0,ProxyUser:m.proxy.username,ProxyPassword:m.proxy.password,Langs:m.langs,AcceptLang:m.langs?m.langs+",q=0.9":"en-US,en;q=0.9",DisabledFonts:(await z()).join(",")};I.default.writeFileSync(r,JSON.stringify(B)),I.default.writeFileSync(i,M(JSON.stringify(Fe))),I.default.writeFileSync(s,M(JSON.stringify(f))),c=M(JSON.stringify({UserId:"1",CanvasMark:(0,w.rAutoDigitInt)("7949",m.fp).toString(),DisableContainer:!0,WebGLFP:r,AudioFp:f.AudioFp,WebGLMark:f.WebGLMark,StartTime:f.StartTime,AllowScanPorts:m.scanPorts,GeolocationSetting:f.GeolocationSetting,FlashPluginSetting:f.FlashPluginSetting,Platform:f.Platform,ScreenSize:f.ScreenSize,DisableBackgroundMode:f.DisableBackgroundMode,DisableWebRTC:f.DisableWebRTC,HardwareConcurrency:f.HardwareConcurrency,DeviceMemory:f.DeviceMemory,LoadExtensionErrorBox:f.LoadExtensionErrorBox,ClientRectFp:f.ClientRectFp,CanvasMarkEx:(0,w.rAutoDigitInt)("7949",m.fp).toString(),WebGLMarkEx:(0,w.rAutoDigitInt)("5001",m.fp).toString(),command_line:{"do-not-de-elevate":""},ProxyChain:[{scheme:m.proxy.protocol,host:m.proxy.host,port:m.proxy.port,account:m.proxy.username,password:m.proxy.password}],ForceProcessExit:f.ForceProcessExit,ProxyUser:f.ProxyUser,ProxyPassword:f.ProxyPassword,Langs:f.Langs,AcceptLang:f.AcceptLang,TimeZone:m.timezone,Geoposition:m.geop,DynamicConfig:i,StaticConfig:s})),I.default.writeFileSync(n,c),a=f.ScreenSize}return{args:["--disable-background-networking","--disable-client-side-phishing-detection","--disable-default-apps","--disable-hang-monitor","--disable-popup-blocking","--disable-prompt-on-repost","--disable-sync","--metrics-recording-only","--no-first-run","--safebrowsing-disable-auto-update","--password-store=basic","--no-service-autorun","--disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes","--force-color-profile=srgb","--use-mock-keychain","--export-tagged-pdf","--no-default-browser-check","--window-position=0,0","--disable-background-mode","--ash-host-window-bounds="+a,"--window-size="+a,"--disable-renderer-accessibility","--disable-legacy-window","--fake-variations-channel=stable","--variations-server-url=https://clientservices.googleapis.com/chrome-variations/seed","--component-updater=initial-delay=6e5","--lang=en-US","--enable-features=NetworkService,NetworkServiceInProcess,LoadCryptoTokenExtension,PermuteTLSExtensions","--enable-blink-features=IdleDetection,Fledge","--extended-parameters="+c,"--flag-switches-begin","--flag-switches-end","--load-extension=","--no-sandbox"],startingUrl:"https://ipapi.co/json/"}}})}var Ee=require("@faker-js/faker"),C=require("@tocha688/utils");var V=g(require("fs"),1),Ne=g(require("path"),1);async function Se(o){return G(o,{prepare:async(t,e)=>{let r;o.proxy&&(r=await(0,C.startProxyServer)(o.proxy),console.log(`Started proxy server on port ${r.port}`));let i=r?.ipinfo;i&&(i=await(0,C.getIpInfo)(i.proxy));let s=Ne.default.join(t,"fingerprint.config"),n;V.default.existsSync(s)?n=V.default.readFileSync(s,"utf-8"):(n=Ee.faker.number.int({min:1e7,max:99999999}).toString(),V.default.writeFileSync(s,n));let c=["--allow-pre-commit-input","--disable-background-networking","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad","--disable-client-side-phishing-detection","--disable-component-extensions-with-background-pages","--disable-crash-reporter","--disable-default-apps","--disable-dev-shm-usage","--disable-hang-monitor","--disable-infobars","--disable-ipc-flooding-protection","--disable-popup-blocking","--disable-prompt-on-repost","--disable-renderer-backgrounding","--disable-search-engine-choice-screen","--disable-sync","--export-tagged-pdf","--force-color-profile=srgb","--generate-pdf-document-outline","--metrics-recording-only","--no-first-run","--password-store=basic","--use-mock-keychain","--disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes","--enable-features=PdfOopif","--fingerprints="+n,"--window-size=1280,720","--window-position=0,0","--no-sandbox","--ignore-certificate-errors","--notice-number=1","--ignores=tls","--enable-logging","--timezone="+(i?.timezone??"America/Los_Angeles"),"--lang=en-US"];return r&&r.port&&c.push(`--proxy-server=http://127.0.0.1:${r.port}`),{args:c,startingUrl:"https://ipapi.co/json/",cleanup:async()=>{r&&await r.server.close(!0)}}}})}async function tt(o){return Se(o)}var Ar=require("chrome-launcher"),Ir=require("proxy-chain");0&&(module.exports={AdsBrowserStartMain,AutoHelper,BrowserCachePath,BrowserPool,Cpus,HumanMouse,LinuxWebGL,Memorys,OKBrowserCreate,OKBrowserStartMain,PcScreen,WindowsWebGL,createBrowser,fetchResource,getBrowserWebSocketUrl,isElementFocused,isLocator,launchBrowserBase,makeUniqueBrowserConfig,rSysFonts,routeAssetsAbort,routeAssetsCache,routeAssetsLocal,splitTextIntoChunks,startLocalBrowser});
|
package/dist/index.d.cts
CHANGED
|
@@ -347,8 +347,8 @@ declare class BrowserPool {
|
|
|
347
347
|
* 用于浏览器缓存
|
|
348
348
|
*/
|
|
349
349
|
|
|
350
|
-
/** 缓存浏览器到目录 ./
|
|
351
|
-
declare function routeAssetsCache(page: Page, cachePath
|
|
350
|
+
/** 缓存浏览器到目录 ./tmps/browser_cache */
|
|
351
|
+
declare function routeAssetsCache(page: Page, cachePath?: string): Promise<void>;
|
|
352
352
|
|
|
353
353
|
declare function fetchResource(route: Route, req: Request, page: Page): Promise<void>;
|
|
354
354
|
declare function routeAssetsLocal(page: Page): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -347,8 +347,8 @@ declare class BrowserPool {
|
|
|
347
347
|
* 用于浏览器缓存
|
|
348
348
|
*/
|
|
349
349
|
|
|
350
|
-
/** 缓存浏览器到目录 ./
|
|
351
|
-
declare function routeAssetsCache(page: Page, cachePath
|
|
350
|
+
/** 缓存浏览器到目录 ./tmps/browser_cache */
|
|
351
|
+
declare function routeAssetsCache(page: Page, cachePath?: string): Promise<void>;
|
|
352
352
|
|
|
353
353
|
declare function fetchResource(route: Route, req: Request, page: Page): Promise<void>;
|
|
354
354
|
declare function routeAssetsLocal(page: Page): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{sleep as A}from"@tocha688/utils";import{rInt as F}from"@tocha688/utils/random";import{Bezier as fe}from"bezier-js";var R=class{page;currentPosition={x:0,y:0};config={minSteps:15,maxSteps:50};constructor(t,e={}){this.page=t,this.currentPosition={x:0,y:0},this.config={minSteps:15,maxSteps:50,...e}}_randomSteps(){return Math.floor(Math.random()*(this.config.maxSteps-this.config.minSteps))+this.config.minSteps}async _toPoint(t,e){let{min:r=.2,max:
|
|
1
|
+
import{sleep as A}from"@tocha688/utils";import{rInt as F}from"@tocha688/utils/random";import{Bezier as fe}from"bezier-js";var R=class{page;currentPosition={x:0,y:0};config={minSteps:15,maxSteps:50};constructor(t,e={}){this.page=t,this.currentPosition={x:0,y:0},this.config={minSteps:15,maxSteps:50,...e}}_randomSteps(){return Math.floor(Math.random()*(this.config.maxSteps-this.config.minSteps))+this.config.minSteps}async _toPoint(t,e){let{min:r=.2,max:i=.8}=e||{},s=await t.boundingBox();if(!s)throw new Error("Element has no bounding box");return{x:s.x+s.width*(r+Math.random()*(i-r)),y:s.y+s.height*(r+Math.random()*(i-r))}}async moveTo(t,e,r={}){let{speed:i=.5,randomness:s=.3}=r,n=this.currentPosition,c={x:t,y:e},a=this.generateControlPoints(n,c,s),p=new fe(...a),l=r.steps||this._randomSteps(),u=p.getLUT(l);for(let m=0;m<u.length;m++){let h=u[m],S=this.getDynamicDelay(m,u.length,i);await this.page.mouse.move(h.x,h.y),await A(S)}this.currentPosition=c}async moveToEl(t,e={}){let r=await this._toPoint(t,e);await this.moveTo(r.x,r.y,e)}async moveBy(t,e,r={}){let i=this.currentPosition.x+t,s=this.currentPosition.y+e;return this.moveTo(i,s,r)}async scrollBy(t,e={}){let{speed:r=.5,randomness:i=.3}=e,s=e.steps||this._randomSteps(),n=t/s;for(let c=0;c<s;c++){let a=n*(Math.random()-.5)*i,p=n+a;await this.page.evaluate("(y) => { window.scrollBy(0, y); }",p);let l=this.getDynamicDelay(c,s,r);await A(l)}}async scrollTo(t,e={}){let r=await this.page.evaluate("() => window.scrollY || document.documentElement.scrollTop || 0"),i=t-r;Math.abs(i)<1||await this.scrollBy(i,e)}async scrollToEl(t,e={}){let i=this.page.viewportSize()?.height??await this.page.evaluate("() => window.innerHeight"),s=await t.evaluate(`(node) => {
|
|
2
2
|
const rect = node.getBoundingClientRect();
|
|
3
3
|
return { top: rect.top + window.scrollY, height: rect.height };
|
|
4
|
-
}`),n=Math.max(0,s.top-
|
|
4
|
+
}`),n=Math.max(0,s.top-i*.3);await this.scrollTo(n,e)}async click(t,e,r={}){let{doubleClick:i=!1,button:s="left"}=r;await this.moveTo(t,e,{steps:r.steps,speed:r.speed,randomness:r.randomness}),await this.page.mouse.down({button:s}),await A(F(50,150)),await this.page.mouse.up({button:s}),i&&(await A(F(100,300)),await this.page.mouse.down({button:s}),await A(F(50,150)),await this.page.mouse.up({button:s}))}async clickEl(t,e={}){try{let r=await this._toPoint(t,e);await this.click(r.x,r.y,e)}catch(r){console.log("clickEl err: ",r,"el: ",t)}}generateControlPoints(t,e,r){let i=Math.hypot(e.x-t.x,e.y-t.y),s={x:t.x+(e.x-t.x)*.3+(Math.random()-.5)*i*r,y:t.y+(e.y-t.y)*.3+(Math.random()-.5)*i*r},n={x:e.x-(e.x-t.x)*.3+(Math.random()-.5)*i*r,y:e.y-(e.y-t.y)*.3+(Math.random()-.5)*i*r};return[t,s,n,e]}getDynamicDelay(t,e,r){let i=t/e,s=10+(1-r)*50;return Math.max(10,s*(1-Math.sin(i*Math.PI))*.5)}getRandomDelay(t=20,e=100){return Math.floor(Math.random()*(e-t+1))+t}async showCursor(){await this.page.addInitScript({content:`
|
|
5
5
|
let dot;
|
|
6
6
|
document.addEventListener('mousemove', (e) => {
|
|
7
7
|
if (!dot) {
|
|
@@ -20,7 +20,7 @@ import{sleep as A}from"@tocha688/utils";import{rInt as F}from"@tocha688/utils/ra
|
|
|
20
20
|
dot.style.left = e.clientX + 'px';
|
|
21
21
|
dot.style.top = e.clientY + 'px';
|
|
22
22
|
});
|
|
23
|
-
`})}},B=R;function k(
|
|
23
|
+
`})}},B=R;function k(o,t){let e=[];for(let r=0;r<o.length;r+=t)e.push(o.slice(r,r+t));return e}async function O(o){try{return await o.evaluate(`(element) => {
|
|
24
24
|
let active = document.activeElement;
|
|
25
25
|
// \u7A7F\u900F Shadow DOM
|
|
26
26
|
while (active && active.shadowRoot && active.shadowRoot.activeElement) {
|
|
@@ -32,8 +32,8 @@ import{sleep as A}from"@tocha688/utils";import{rInt as F}from"@tocha688/utils/ra
|
|
|
32
32
|
if (element.contains(active)) return true;
|
|
33
33
|
|
|
34
34
|
return false;
|
|
35
|
-
}`)}catch{return!1}}function _(
|
|
35
|
+
}`)}catch{return!1}}function _(o){return o&&typeof o=="object"&&"_frame"in o&&"_selector"in o}async function y(o,t,e,r){typeof e=="string"&&(e=o.locator(e));let{scrollTimeout:i=6e4,skipScroll:s=!1,...n}=r||{};if(await e.waitFor({state:"visible",...r}),await e.waitFor({state:"attached",...r}),!s)try{await e.scrollIntoViewIfNeeded({timeout:i})}catch(c){console.warn(`\u6EDA\u52A8\u8D85\u65F6(${i}ms)\uFF0C\u5C1D\u8BD5\u7EE7\u7EED\u6267\u884C:`,c.message);try{await e.evaluate(`
|
|
36
36
|
(el) => {
|
|
37
37
|
el.scrollIntoView({ behavior: "auto", block: "center" });
|
|
38
38
|
}
|
|
39
|
-
`),await i.waitForTimeout(500)}catch(a){console.warn("\u7B80\u5355\u6EDA\u52A8\u4E5F\u5931\u8D25\uFF0C\u5F3A\u5236\u7EE7\u7EED:",a.message)}}return await t.clickEl(e,r)}async function U(i,t,e,r){return await i.click(t,e,r)}import{cancelableFunction as he}from"@tocha688/utils/sync";import{rInt as ge}from"@tocha688/utils";async function D(i=200,t=800){let e=ge(i,t);return new Promise(r=>setTimeout(r,e))}async function H(i,t="load",e=3e4){let r=t.toUpperCase();try{return console.log(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] \u76EE\u6807\u72B6\u6001: ${r}, \u8D85\u65F6: ${e/1e3}s`),await i.waitForLoadState(t,{timeout:e}),console.log(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] ${r} \u72B6\u6001\u5DF2\u5B8C\u6210\u3002`),!0}catch{return console.error(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] ${r} \u72B6\u6001\u5931\u8D25\u6216\u8D85\u65F6\u3002`),!1}}function X(i,t,e,r={}){return new Promise(async(o,s)=>{let{frameAttachedTimeout:n=45e3,frameVisibleTimeout:c=1e4,frameBodyTimeout:a=15e3,frameInLocatorOptions:p={},waitForElementTimeout:l=15e3,timeout:u=2e3}=r;console.log(`[\u7B49\u5F85 ${String(t)} iframe \u5B8C\u5168\u52A0\u8F7D]`);try{console.log("\u7B49\u5F85 iframe \u5143\u7D20..."),await i.waitForSelector(String(t),{state:"attached",timeout:n}),console.log("\u7B49\u5F85 iframe \u53EF\u89C1..."),await i.waitForSelector(String(t),{state:"visible",timeout:c}),console.log("\u2705 iframe \u53EF\u89C1");let m=i.frameLocator(String(t));await m.locator("body").waitFor({state:"attached",timeout:a}),console.log("\u2705 iframe \u5185\u5BB9\u5DF2\u52A0\u8F7D"),console.log(`[\u7B49\u5F85\u6307\u5B9A\u5143\u7D20\u53EF\u89C1] ${String(e)}`),await m.locator(e,p).waitFor({timeout:l}),console.log("[\u7B49\u5F85\u5B8C\u5168\u52A0\u8F7D]"),await i.waitForTimeout(u),o(m)}catch(m){s(m)}})}function W(i,t={}){return he(async e=>{let r=Date.now();for(;e.signal.aborted===!1&&Date.now()-r<(t.timeout||3e4);){if(await i.isVisible().catch(()=>!1))return i;await D(100)}throw new Error("waitForAbort \u8D85\u65F6")})}import{rInt as $}from"@tocha688/utils";async function q(i,t,e,r,o){if(typeof e=="string"&&(e=i.locator(e)),!_(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{clear:s=!0,delay:n={min:50,max:150},retries:c=3,...a}=o||{};if(await e.waitFor({state:"visible",...a}),await e.waitFor({state:"attached",...a}),await y(i,t,e,a),await D(50,100),s){let l=await e.inputValue().catch(()=>"");l&&l.length>0&&(await e.click({clickCount:3}),await D(20,50),await i.keyboard.press("Delete"),await D(20,50))}let p=k(r,5);for(let l=0;l<p.length;l++){let u=p[l];if(!await O(e)){await y(i,t,e,a);let h=await e.inputValue().catch(()=>"");h&&h.length>0&&await i.keyboard.press("End"),await D(30,60)}u&&await e.pressSequentially(u,{delay:$(n.min,n.max)}),l<p.length-1&&await D(50,150)}await D(100,200),await e.blur()}async function j(i,t,e,r,o){if(typeof e=="string"&&(e=i.locator(e)),!_(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{clear:s=!0,delay:n={min:50,max:150},retries:c=3,...a}=o||{};if(await e.waitFor({state:"visible",...a}),await e.waitFor({state:"attached",...a}),await y(i,t,e,a),await D(50,100),s){let l=await e.inputValue().catch(()=>"");l&&l.length>0&&(await e.click({clickCount:3}),await D(20,50),await i.keyboard.press("Delete"),await D(20,50))}let p=k(r,5);for(let l=0;l<p.length;l++){let u=p[l];u&&await e.pressSequentially(u,{delay:$(n.min,n.max)}),l<p.length-1&&await D(50,150)}await D(100,200),await e.blur()}async function z(i,t,e,r,o){if(typeof e=="string"&&(e=i.locator(e)),!_(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{retries:s=3,verify:n=!0,...c}=o||{};await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c});try{let p=await e.inputValue(),l=typeof r=="string"?r:Array.isArray(r)?r[0]?.toString():r?.toString();if(p===l)return}catch(p){console.warn(`\u83B7\u53D6\u5F53\u524D\u9009\u62E9\u503C\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await y(i,t,e,c),await D(50,100),await e.selectOption(r,c),await D(100,200),n){let p=await e.inputValue(),l=typeof r=="string"?r:Array.isArray(r)?r[0]?.toString():r?.toString();if(p!==l)throw new Error(`\u9009\u62E9\u9A8C\u8BC1\u5931\u8D25: \u671F\u671B"${l}", \u5B9E\u9645"${p}"`)}await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u9009\u62E9\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}async function J(i,t,e,r){if(typeof e=="string"&&(e=i.locator(e)),!_(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{force:o=!1,retries:s=3,verify:n=!0,...c}=r||{};if(await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c}),!o)try{if(await e.isChecked())return}catch(p){console.warn(`\u68C0\u67E5\u52FE\u9009\u72B6\u6001\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await y(i,t,e,c),await D(50,100),await e.check({force:o,...c}),await D(100,200),n&&!await e.isChecked())throw new Error("\u52FE\u9009\u9A8C\u8BC1\u5931\u8D25: \u5143\u7D20\u672A\u88AB\u6210\u529F\u52FE\u9009");await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u52FE\u9009\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}async function K(i,t,e,r){if(typeof e=="string"&&(e=i.locator(e)),!_(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{force:o=!1,retries:s=3,verify:n=!0,...c}=r||{};if(await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c}),!o)try{if(!await e.isChecked())return}catch(p){console.warn(`\u68C0\u67E5\u52FE\u9009\u72B6\u6001\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await y(i,t,e,c),await D(50,100),await e.uncheck({force:o,...c}),await D(100,200),n&&await e.isChecked())throw new Error("\u53D6\u6D88\u52FE\u9009\u9A8C\u8BC1\u5931\u8D25: \u5143\u7D20\u4ECD\u7136\u88AB\u52FE\u9009");await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u53D6\u6D88\u52FE\u9009\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}function Y(i,t,e,r={}){let{interval:o=1e3,debug:s=!1}=r,n=[],c=!0,a=u=>{let m=u.url();(t instanceof RegExp?t.test(m):m.includes(t))&&(s&&console.log(`[Collector] \u6355\u83B7\u5230\u76EE\u6807\u8BF7\u6C42: ${m}`),n.push(u))};i.on("request",a);let p=setInterval(async()=>{if(c)for(s&&console.log(`[Poller] \u8F6E\u8BE2\u68C0\u67E5\u4E2D... \u5F53\u524D\u961F\u5217\u79EF\u538B: ${n.length}`);n.length>0;){let u=n.shift();if(u)if(e)await e(u);else{let m=`[Error] \u81F4\u547D\u9519\u8BEF: \u68C0\u6D4B\u5230\u88AB\u7981\u6B62\u7684\u8BF7\u6C42/\u672A\u5904\u7406\u7684\u8BF7\u6C42\u53D1\u9001! URL: ${u.url()}`;console.error(m),l()}}},o),l=()=>{c&&(c=!1,clearInterval(p),i.off("request",a),s&&console.log("[Poller] \u76D1\u542C\u5DF2\u505C\u6B62"))};return{stop:l}}function Q(i,t,e,r={}){let{interval:o=1e3,debug:s=!1}=r,n=!0,c=!1;s&&console.log(`[ElementMonitor] \u5F00\u59CB\u76D1\u542C\u5143\u7D20: "${t}"`);let a=setInterval(async()=>{if(!(!n||c))try{if(i.isClosed()){p();return}if(await i.isVisible(t))if(s&&console.log(`[ElementMonitor] \u53D1\u73B0\u76EE\u6807\u5143\u7D20: "${t}"`),c=!0,e)try{await e(i.locator(t))}catch(u){console.error(`[Callback Error] \u5904\u7406\u5143\u7D20 "${t}" \u56DE\u8C03\u5931\u8D25:`,u)}finally{c=!1}else{let u=`[Error] \u81F4\u547D\u9519\u8BEF: \u9875\u9762\u51FA\u73B0\u4E86\u4E0D\u8BE5\u51FA\u73B0\u7684\u5143\u7D20! Selector: "${t}"`;console.error(u),p()}}catch(l){s&&console.warn("[ElementMonitor] \u8F6E\u8BE2\u68C0\u67E5\u5F02\u5E38:",l)}},o),p=()=>{n&&(n=!1,clearInterval(a),s&&console.log(`[ElementMonitor] \u505C\u6B62\u76D1\u542C\u5143\u7D20: "${t}"`))};return{stop:p}}import{rInt as x,sleep as Z}from"@tocha688/utils";async function ee(i,t,e){let r=0,o=t+x(-100,100);if(console.log(`\u5F00\u59CB\u6A21\u62DF\u6EDA\u52A8\uFF0C\u76EE\u6807\u8DDD\u79BB: ${o}px`),e){let n=await e.boundingBox();if(n){let c=n.x+n.width/2+x(-10,10),a=n.y+n.height/2+x(-10,10);await i.mouse.move(c,a)}else console.warn("Target locator provided but element is not visible/present. Falling back to global scroll.")}let s=async n=>{await i.mouse.wheel(0,n),!e&&Math.random()<.3&&await i.mouse.move(x(100,500),x(100,500))};for(;r<o;){let n=x(50,150);r+n>o&&(n=o-r),await s(n),r+=n,Math.random()<.1?await Z(x(500,800)):await Z(x(30,100))}console.log("\u6EDA\u52A8\u5B8C\u6210")}var Ie="_ah_",L=class i{page;mouse;constructor(t){this.page=t,this.mouse=new B(t)}static create(t){let e=new i(t),r=Object.create(t);return Object.assign(r,t),Object.assign(r,e),["locator","getByRole","getByTestId","getByLabel","getByPlaceholder","getByText","getByAltText","getByTitle"].forEach(s=>{if(!t[s])return;let c=t[s].bind(t),a=Ie+s;r[a]=c,r[s]=function(...p){let l=r[a](...p);return l&&e.enhanceLocator(l)}}),r}enhanceLocator(t){let e=Object.create(t);return Object.assign(e,t),e._loc=t,e.click=this.click.bind(this,t),e.input=e.fill=this.input.bind(this,t),e.selectOption=e.select=this.select.bind(this,t),e.check=this.check.bind(this,t),e.uncheck=this.uncheck.bind(this,t),e}async click(t,e){return y(this.page,this.mouse,t,e)}async clickPoint(t,e,r){return U(this.mouse,t,e,r)}isLocator(t){return _(t)}async input(t,e,r){return q(this.page,this.mouse,t,e,r)}async inputFofce(t,e,r){return j(this.page,this.mouse,t,e,r)}async select(t,e,r){return z(this.page,this.mouse,t,e,r)}async check(t,e){return J(this.page,this.mouse,t,e)}async uncheck(t,e){return K(this.page,this.mouse,t,e)}async rWait(t=200,e=800){return D(t,e)}async safeWaitForLoadState(t="load",e=3e4){return H(this.page,t,e)}waitForIframeComplete(t,e,r={}){return X(this.page,t,e,r)}startRequestPolling(t,e,r={}){return Y(this.page,t,e,r)}startElementPolling(t,e,r,o={}){return Q(t,e,r,o)}waitForAbort(t,e={}){return W(t,e)}async humanScroll(t,e){return ee(this.page,t,e)}};import ve from"path";var Ft=ve.join(process.cwd(),"tmp","browser_cache");import Pe from"path";import{chromium as Le}from"patchright-core";function te(){let i=`${Date.now()}-${Math.random().toString(36).slice(2)}`,t=Pe.join(process.cwd(),"tmps",`brw-session-${i}`);return{sessionId:i,userDataDir:t}}async function I(i){return(await fetch(`http://127.0.0.1:${i}/json/version`).then(e=>e.json()))?.webSocketDebuggerUrl||""}async function M(i,t){let e=await i({...t}),r=await I(e.port);if(!r)throw e.close(),new Error("\u65E0\u6CD5\u83B7\u53D6\u6D4F\u89C8\u5668WebSocket URL");try{let o=await Le.connectOverCDP(r),s=o.contexts()[0]?.pages()?.[0]??await o.newPage();s.setDefaultNavigationTimeout(6e4),s.setDefaultTimeout(6e4);let n=new L(s);return o._hk_close=o.close,o.close=async function(){await o._hk_close(),await e.close()},{page:s,auto:n,brw:o}}catch(o){return console.log(o),await e.close(),await M(i,t)}}import{createPool as Ge}from"generic-pool";var re=class{constructor(t,e,r={}){this.startFn=t;this.opts=e;this.pool=Ge({create:async()=>await M(this.startFn,this.opts),destroy:async o=>{await o.brw.close()},validate:async o=>o.brw.isConnected()},{min:r.min??1,max:r.max??5,testOnBorrow:r.testOnBorrow??!0,idleTimeoutMillis:r.idleTimeoutMillis??3e4})}pool;async acquire(){let t=await this.pool.acquire();return{...t,release:async()=>{await this.pool.release(t)}}}async drain(){await this.pool.drain(),await this.pool.clear()}async use(t){let e=await this.acquire();try{return await t(e)}finally{await e.release()}}};import"patchright-core";import g from"fs";import Ee from"path";import{createHash as Ne}from"crypto";function oe(i,t){let e=Ne("md5").update(i).digest("hex"),r=Ee.join(t,e),o=r+".meta.json";return{cacheFile:r,metaFile:o}}async function Yt(i,t){g.existsSync(t)||g.mkdirSync(t,{recursive:!0}),console.log("\u542F\u7528\u6D4F\u89C8\u5668\u7F13\u5B58"),await i.route("**/*",async e=>{let r=e.request();if(r.method()!=="GET")return e.continue();let o=r.resourceType();if(["xhr","fetch","websocket","document"].includes(o))return e.continue();let s=r.url(),{cacheFile:n,metaFile:c}=oe(s,t);try{if(g.existsSync(n)&&g.existsSync(c)){let a=JSON.parse(g.readFileSync(c,"utf-8")),p=g.readFileSync(n);return Date.now()-a.timestamp>a.timeout?(g.unlinkSync(n),g.unlinkSync(c),e.continue()):e.fulfill({status:200,headers:a.headers,body:p,contentType:a.contentType})}}catch{}return e.continue()}),await i.on("response",async e=>{let r=e.request();if(r.method()!=="GET")return;let o=e.status();if(![200,201].includes(o))return;let s=e.url(),{cacheFile:n,metaFile:c}=oe(s,t);if(g.existsSync(n)&&g.existsSync(c))return;let a=e.headers();if((a["content-type"]||"").includes("text/plain")||s.includes(";"))return;let l=a["cache-control"]||"",u=a.pragma||"";if(l.includes("no-store")||u.includes("no-cache"))return;let m=r.resourceType();if(!(!(u||l)&&(["xhr","fetch","websocket","document"].includes(m)||new URL(s).searchParams.toString().length>0)))try{let h=await e.body();g.writeFileSync(n,h),g.writeFileSync(c,JSON.stringify({url:s,headers:a,contentType:a["content-type"],timestamp:Date.now(),timeout:parseInt(a["cache-control"]?.match(/max-age=(\d+)/)?.[1]||"99999999")*1e3}))}catch{}})}async function Se(i,t,e){return await fetch(t.url(),{method:t.method(),body:t.postData(),headers:t.headers()}).then(async r=>i.fulfill({status:r.status,headers:Object.fromEntries(r.headers.entries()),body:Buffer.from(await r.arrayBuffer())})).catch(()=>i.abort())}async function er(i){await i.route("**/*",async t=>{let e=t.request(),r=e.url(),o=e.resourceType();return["GET"].includes(e.method())?["xhr","fetch","websocket","document"].includes(o)||["script"].includes(o)&&r.includes("?")?await t.continue():await Se(t,e,i):await t.continue()})}async function tr(i){await i.route("**/*",async t=>{let e=t.request();if(e.method()!=="GET")return t.continue();let r=e.resourceType();return["xhr","fetch","websocket","document","script"].includes(r)?t.continue():t.abort()})}import*as ie from"chrome-launcher";import{chromium as Fe}from"patchright-core";async function nr(i){let{chromePath:t,headless:e=!1,userDataDir:r}=i,o=["--disable-blink-features=AutomationControlled","--no-sandbox","--disable-setuid-sandbox"];e&&o.push("--headless");let s=await ie.launch({chromePath:t,chromeFlags:o,userDataDir:r}),n=await I(s.port);return{userDataDir:r||"",port:s.port,browser:s,wsUrl:n,close:async()=>await s.kill(),async mainPage(){let c=await Fe.connectOverCDP(n),a=c.contexts()?.[0]??await c.newContext();return a?.pages()?.[0]??await a.newPage()}}}import b from"fs";import N from"path";import{faker as De}from"@faker-js/faker";function G(i){let t,e;t===void 0&&(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),e===void 0&&(e="hTy1bfRJz4nLPcBCO7WtmNIaGvVeul5Zo8kq32UxrYw_-0gsjp96SDFXQiEMKdHA");var r=t,o=e,s=Buffer.from(i).toString("base64").split(""),n="";return s.map((function(c){var a=r.indexOf(c);return n+=a<0?c:o.substr(a,1),c})),n}function se(i){let t,e;if(t===void 0&&(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),e===void 0&&(e="hTy1bfRJz4nLPcBCO7WtmNIaGvVeul5Zo8kq32UxrYw_-0gsjp96SDFXQiEMKdHA"),!i)return"";var r=t,o=e,s=i.split(""),n="";return s.map((function(c){var a=o.indexOf(c);return n+=a<0?c:r.substr(a,1),c})),Buffer.from(n,"base64").toString()}import Re from"font-list";import{rInt as ne}from"@tocha688/utils";var ae=["750 \xD7 1334","800 x 600","1024 x 600","1024 x 640","1024 x 768","1152 x 864","1280 x 720","1280 x 768","1280 x 800","1280 x 960","1280 x 1024","1360 x 768","808 \xD7 1792","828 \xD7 1792","1080 x 2340","1125 x 2436","1242 x 2208","1170 \xD7 2532","1284 x 2778","1366 x 768","1400 x 1050","1400 x 900","1440 x 900","1536 x 864","1600 x 900","1600 x 1200","1680 x 1050","1920 x 1080","1920 x 1200","2048 x 1152","2304 x 1440","2560 x 1440","2560 x 1600","2880 x 1800","4096 x 2304","5120 x 2880"],ce=["2","3","4","6","8","10","12","16","20","24","32","64"],Dr=["2","4","6","8","16","32","64","128"],dr=[{name:"Google Inc. (AMD)",values:["ANGLE (AMD, RENOIR(renoir LLVM 15.0.7), OpenGL 4.6)"]},{name:"Google Inc. (Intel)",values:["ANGLE (Intel, Mesa Intel(R) Graphics (RPL-S), OpenGL 4.6)","ANGLE (Intel, Mesa Intel(R) Graphics (RPL-P), OpenGL 4.6)","ANGLE (Intel, Mesa Intel(R) Xe Graphics (TGL GT2), OpenGL 4.6)"]}],le=[{name:"Google Inc. (NVIDIA)",vendor:"nvidia",values:["ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 SUPER (0x000021C4) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6647)","ANGLE (NVIDIA, NVIDIA GeForce GTX 750 Ti (0x00001380) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6647)","ANGLE (NVIDIA, NVIDIA GeForce GTX 650 (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6140)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 Ti (0x00001C8C) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (NVIDIA, NVIDIA GeForce GT 635M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.13.6472)","ANGLE (NVIDIA, NVIDIA GeForce GT 710 (0x0000128B) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.3160)","ANGLE (NVIDIA, NVIDIA GeForce 410M (0x00001055) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6093)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1060 (0x00001C20) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5148)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 (0x00002184) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5751)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2070 SUPER (0x00001E84) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 750 Ti (0x00001380) Direct3D9Ex vs_3_0 ps_3_0, nvd3dumx.dll-26.21.14.4219)","ANGLE (NVIDIA, NVIDIA GeForce GT 730 (0x00001287) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 (0x00001F9D) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5751)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 (0x00001C91) Direct3D11 vs_5_0 ps_5_0, D3D11-22.21.13.8476)","ANGLE (NVIDIA, NVIDIA GeForce GTX 950 (0x00001402) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4187)","ANGLE (NVIDIA, NVIDIA GeForce GTX 960 (0x00001401) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce RTX 3070 (0x00002484) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6611)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5256)","ANGLE (NVIDIA, NVIDIA GeForce GTX 660 (0x000011C0) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 970 (0x000013C2) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 (0x00001F9D) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5256)","ANGLE (NVIDIA, NVIDIA GeForce 205 (0x00002504) Direct3D11 vs_4_1 ps_4_1, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1070 (0x00001BA1) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA Quadro K620 (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1060 3GB (0x00001C02) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (NVIDIA, NVIDIA GeForce GT 635M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-23.21.13.9124)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 (0x00001C91) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.3630)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4250)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 SUPER (0x00001F47) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5167)","ANGLE (NVIDIA, NVIDIA Quadro P600 (0x00001CB2) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5239)","ANGLE (NVIDIA, NVIDIA Quadro M1000M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 550 Ti (0x00001244) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce 210 (0x00000A65) Direct3D11 vs_4_0 ps_4_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 SUPER (0x00002187) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4120)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 Ti (0x00002191) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GT 1030 (0x00001D01) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 970 (0x000013C2) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1070 (0x00001BA1) Direct3D11 vs_5_0 ps_5_0, D3D11-23.21.13.8813)","ANGLE (NVIDIA, NVIDIA GeForce GT 730 (0x00001287) Direct3D11 vs_5_0 ps_5_0, D3D11-9.18.13.4411)"]},{name:"Google Inc. (AMD)",vendor:"amd",values:["ANGLE (AMD, AMD Radeon(TM) RX 560 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Mobile Graphics (0x000015DD) Direct3D9Ex vs_3_0 ps_3_0, D3D11)","ANGLE (AMD, Radeon RX RX550/550 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon R7 350 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.15029.27017)","ANGLE (AMD, AMD Radeon(TM) R7 Graphics (0x0000130F) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1034.6)","ANGLE (AMD, Radeon RX 560 Series (0x000067EF) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.15029.27017)","ANGLE (AMD, AMD Radeon HD 7800 Series (0x00006819) Direct3D9Ex vs_3_0 ps_3_0, aticfx64.dll-26.20.15029.15007)","ANGLE (AMD, AMD Radeon RX 580 2048SP (0x00006FDF) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.15003.5017)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14501.18003)","ANGLE (AMD, AMD Radeon(TM) Graphics (0x0000164E) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14044.2001)","ANGLE (AMD, AMD Radeon Series (0x00001636) Direct3D9Ex vs_3_0 ps_3_0, aticfx32.dll-23.20.15002.11)","ANGLE (AMD, Radeon (TM) RX 470 Graphics (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.13031.18002)","ANGLE (AMD, AMD Radeon HD 6530D (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, Radeon RX 580 Series (0x000067DF) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14534.2)","ANGLE (AMD, AMD Radeon(TM) RX Vega 10 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.14132.2002)","ANGLE (AMD, AMD Radeon R7 430 (0x00006611) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon (TM) R9 200 Series (0x00006811) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1034.6)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.11008.3003)","ANGLE (AMD, AMD Radeon(TM) RX Vega 10 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1028.1)","ANGLE (AMD, AMD Radeon(TM) Graphics (0x0000164E) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1020.2002)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon R7 200 Series (0x00006658) Direct3D11 vs_5_0 ps_5_0, D3D11)"]},{name:"Google Inc. (Intel)",vendor:"Intel",values:["ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.100.6617)","ANGLE (Intel, Intel(R) UHD Graphics 620 (0x00003EA0) Direct3D11 vs_5_0 ps_5_0, D3D11-24.20.100.6346)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.100.7637)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.8682)","ANGLE (Intel, Intel(R) HD Graphics Family (0x00000A16) Direct3D9Ex vs_3_0 ps_3_0, igdumdim64.dll-10.18.10.3907)","ANGLE (Intel, Intel(R) HD Graphics 4000 (0x00000162) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.4252)","ANGLE (Intel, Intel(R) HD Graphics 530 (0x0000191B) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.4364)","ANGLE (Intel, Intel(R) UHD Graphics 620 (0x00003EA0) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.9126)","ANGLE (Intel, Intel(R) UHD Graphics (0x00009BA4) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.100.7985)","ANGLE (Intel, Intel(R) HD Graphics Family (0x00000A16) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.5058)","ANGLE (Intel, Intel(R) UHD Graphics 610 (0x00003EA1) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.100.6471)","ANGLE (Intel, Intel(R) HD Graphics 4600 (0x00000416) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.14.5067)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.9466)","ANGLE (Intel, Intel(R) HD Graphics 4400 (0x0000041E) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.3412)","ANGLE (Intel, Intel(R) Iris(TM) Graphics 6100 (0x00007DD5) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (Intel, Intel(R) Iris(R) Plus Graphics (0x00008A5A) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.8853)","ANGLE (Intel, Intel(R) HD Graphics 520 (0x00001921) Direct3D11 vs_5_0 ps_5_0, D3D11-21.20.16.4727)","ANGLE (Intel, Intel(R) Iris(R) Plus Graphics (0x00008A5A) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5059)","ANGLE (Intel, Intel(R) HD Graphics 5300 (0x00007DD5) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.4531)","ANGLE (Intel, Intel(R) HD Graphics 4000 (0x00000162) Direct3D9Ex vs_3_0 ps_3_0, igdumd64.dll-9.17.10.2849)"]}];async function pe(){let t=(await Re.getFonts()).filter(o=>!/[\u4e00-\u9fa5]/.test(o)),e=ne(5,Math.min(50,t.length)),r=[...t];for(let o=r.length-1;o>0;o--){let s=ne(0,o),n=r[o];r[o]=r[s],r[s]=n}return r.slice(0,e)}import{checkAutoProxy as Te,rArrItem as v,rInt as Ve,rAutoDigitInt as P,getIpInfo as Ce}from"@tocha688/utils";import ke from"portfinder";import T from"fs";import*as ue from"chrome-launcher";import{tryCatch as V,tryLoop as me}from"@tocha688/utils";import{chromium as Me}from"patchright-core";async function E(i,t){let{userDataDir:e}=te();T.mkdirSync(e,{recursive:!0});let r;try{let o=await ke.getPortPromise({port:41e3,stopPort:49999});r=await t.prepare(e,o);let s=[`--user-data-dir=${e}`,`--remote-debugging-port=${o}`,"--remote-debugging-address=0.0.0.0",...r.args];i.headless!==!1&&!s.some(a=>a.startsWith("--headless"))&&s.push("--headless");let n=await ue.launch({userDataDir:e,port:o,chromePath:i.chromePath,chromeFlags:s,startingUrl:r.startingUrl||"about:blank"}),c=await I(n.port);return{userDataDir:e,port:n.port,browser:n,wsUrl:c,close:async()=>{await V(async()=>await n.kill()),r?.cleanup&&await V(r.cleanup),await me(async()=>T.rmSync(e,{recursive:!0,force:!0}))},async mainPage(){let a=await Me.connectOverCDP(c),p=a.contexts()?.[0]??await a.newContext();return p?.pages()?.[0]??await p.newPage()}}}catch(o){throw await me(async()=>T.rmSync(e,{recursive:!0,force:!0})),r?.cleanup&&await V(r.cleanup),o}}async function Tr(i){return E(i,{prepare:async(t,e)=>{let r=N.join(t,"webgl.json"),o=N.join(t,"dynamic.config"),s=N.join(t,"static.config"),n=N.join(t,"params.config"),c,a;if(b.existsSync(n))c=b.readFileSync(n,"utf-8"),a=JSON.parse(se(c)).ScreenSize;else{let l={},u;i.proxy?(l=await Te(i.proxy),u=new URL(l.proxy)):l=await Ce(l.proxy);let m={fp:Ve(1e5,999999),geop:l?.latitude?l?.latitude+","+l?.longitude:"",device_name:"PC"+De.string.alphanumeric(8).toUpperCase(),timezone:l?.timezone||l?.timeZone||"America/Los_Angeles",proxy:{protocol:u?.protocol.replace(":","")||"http",host:u?.hostname||"127.0.0.1",port:u?.port||"8080",username:u?.username||"",password:u?.password||""},mac:De.internet.mac(),scanPorts:"",screenSize:v(ae),langs:l?.languages??"en-US,en"},h=v(le),S={UNMASKED_VENDOR_WEBGL:h.name,UNMASKED_RENDERER_WEBGL:v(h.values),GPUAdapterInfo:{vendor:h.vendor,architecture:"pascal"},SUPPORTED_EXTENSIONS:[]},de={BlockList:{Version:"1743148877",Domains:[]},StrongBlockList:{Version:"3",Domains:[]},TimeZone:m.timezone,Geoposition:m.geop},w={CookiesExportPath:"",SecurePreferenceSync:!0,PasswordExportPath:"",PasswordImportPath:"",RestoreLastSession:!0,BlockPage:"NDA0",FoceSafeBrowsing:!0,ExtensionSetting:[],DisCanvasUrl:"",MaxTouchPoints:0,MediaDevices:[{kind:"audioinput",label:"Microphone Array (Realtek(R) Audio)"},{kind:"videoinput",label:"Integrated Camera (98da:3959)"},{kind:"audiooutput",label:"Speakers (Realtek(R) Audio)"}],AudioFp:P(980,m.fp),WebGLMark:"5001",StartTime:Math.floor(Date.now()/1e3),GeolocationSetting:"ask",FlashPluginSetting:"block",Platform:"Win32",ScreenSize:m.screenSize,DisableBackgroundMode:!0,DisableWebRTC:!0,HardwareConcurrency:v(ce),DeviceMemory:v([4,8]),LoadExtensionErrorBox:!1,ClientRectFp:P("5001",m.fp).toString(),ForceProcessExit:!0,ProxyUser:m.proxy.username,ProxyPassword:m.proxy.password,Langs:m.langs,AcceptLang:m.langs?m.langs+",q=0.9":"en-US,en;q=0.9",DisabledFonts:(await pe()).join(",")};b.writeFileSync(r,JSON.stringify(S)),b.writeFileSync(o,G(JSON.stringify(de))),b.writeFileSync(s,G(JSON.stringify(w))),c=G(JSON.stringify({UserId:"1",CanvasMark:P("7949",m.fp).toString(),DisableContainer:!0,WebGLFP:r,AudioFp:w.AudioFp,WebGLMark:w.WebGLMark,StartTime:w.StartTime,AllowScanPorts:m.scanPorts,GeolocationSetting:w.GeolocationSetting,FlashPluginSetting:w.FlashPluginSetting,Platform:w.Platform,ScreenSize:w.ScreenSize,DisableBackgroundMode:w.DisableBackgroundMode,DisableWebRTC:w.DisableWebRTC,HardwareConcurrency:w.HardwareConcurrency,DeviceMemory:w.DeviceMemory,LoadExtensionErrorBox:w.LoadExtensionErrorBox,ClientRectFp:w.ClientRectFp,CanvasMarkEx:P("7949",m.fp).toString(),WebGLMarkEx:P("5001",m.fp).toString(),command_line:{"do-not-de-elevate":""},ProxyChain:[{scheme:m.proxy.protocol,host:m.proxy.host,port:m.proxy.port,account:m.proxy.username,password:m.proxy.password}],ForceProcessExit:w.ForceProcessExit,ProxyUser:w.ProxyUser,ProxyPassword:w.ProxyPassword,Langs:w.Langs,AcceptLang:w.AcceptLang,TimeZone:m.timezone,Geoposition:m.geop,DynamicConfig:o,StaticConfig:s})),b.writeFileSync(n,c),a=w.ScreenSize}return{args:["--disable-background-networking","--disable-client-side-phishing-detection","--disable-default-apps","--disable-hang-monitor","--disable-popup-blocking","--disable-prompt-on-repost","--disable-sync","--metrics-recording-only","--no-first-run","--safebrowsing-disable-auto-update","--password-store=basic","--no-service-autorun","--disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes","--force-color-profile=srgb","--use-mock-keychain","--export-tagged-pdf","--no-default-browser-check","--window-position=0,0","--disable-background-mode","--ash-host-window-bounds="+a,"--window-size="+a,"--disable-renderer-accessibility","--disable-legacy-window","--fake-variations-channel=stable","--variations-server-url=https://clientservices.googleapis.com/chrome-variations/seed","--component-updater=initial-delay=6e5","--lang=en-US","--enable-features=NetworkService,NetworkServiceInProcess,LoadCryptoTokenExtension,PermuteTLSExtensions","--enable-blink-features=IdleDetection,Fledge","--extended-parameters="+c,"--flag-switches-begin","--flag-switches-end","--load-extension=","--no-sandbox"],startingUrl:"https://ipapi.co/json/"}}})}import{faker as Be}from"@faker-js/faker";import{getIpInfo as Oe,startProxyServer as Ue}from"@tocha688/utils";import C from"fs";import He from"path";async function Xe(i){return E(i,{prepare:async(t,e)=>{let r;i.proxy&&(r=await Ue(i.proxy),console.log(`Started proxy server on port ${r.port}`));let o=r?.ipinfo;o&&(o=await Oe(o.proxy));let s=He.join(t,"fingerprint.config"),n;C.existsSync(s)?n=C.readFileSync(s,"utf-8"):(n=Be.number.int({min:1e7,max:99999999}).toString(),C.writeFileSync(s,n));let c=["--allow-pre-commit-input","--disable-background-networking","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad","--disable-client-side-phishing-detection","--disable-component-extensions-with-background-pages","--disable-crash-reporter","--disable-default-apps","--disable-dev-shm-usage","--disable-hang-monitor","--disable-infobars","--disable-ipc-flooding-protection","--disable-popup-blocking","--disable-prompt-on-repost","--disable-renderer-backgrounding","--disable-search-engine-choice-screen","--disable-sync","--export-tagged-pdf","--force-color-profile=srgb","--generate-pdf-document-outline","--metrics-recording-only","--no-first-run","--password-store=basic","--use-mock-keychain","--disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes","--enable-features=PdfOopif","--fingerprints="+n,"--window-size=1280,720","--window-position=0,0","--no-sandbox","--ignore-certificate-errors","--notice-number=1","--ignores=tls","--enable-logging","--timezone="+(o?.timezone??"America/Los_Angeles"),"--lang=en-US"];return r&&r.port&&c.push(`--proxy-server=http://127.0.0.1:${r.port}`),{args:c,startingUrl:"https://ipapi.co/json/",cleanup:async()=>{r&&await r.server.close(!0)}}}})}async function Wr(i){return Xe(i)}import"chrome-launcher";import"proxy-chain";export{Tr as AdsBrowserStartMain,L as AutoHelper,Ft as BrowserCachePath,re as BrowserPool,ce as Cpus,R as HumanMouse,dr as LinuxWebGL,Dr as Memorys,Wr as OKBrowserCreate,Xe as OKBrowserStartMain,ae as PcScreen,le as WindowsWebGL,M as createBrowser,Se as fetchResource,I as getBrowserWebSocketUrl,O as isElementFocused,_ as isLocator,E as launchBrowserBase,te as makeUniqueBrowserConfig,pe as rSysFonts,tr as routeAssetsAbort,Yt as routeAssetsCache,er as routeAssetsLocal,k as splitTextIntoChunks,nr as startLocalBrowser};
|
|
39
|
+
`),await o.waitForTimeout(500)}catch(a){console.warn("\u7B80\u5355\u6EDA\u52A8\u4E5F\u5931\u8D25\uFF0C\u5F3A\u5236\u7EE7\u7EED:",a.message)}}return await t.clickEl(e,r)}async function U(o,t,e,r){return await o.click(t,e,r)}import{cancelableFunction as he}from"@tocha688/utils/sync";import{rInt as ge}from"@tocha688/utils";async function D(o=200,t=800){let e=ge(o,t);return new Promise(r=>setTimeout(r,e))}async function H(o,t="load",e=3e4){let r=t.toUpperCase();try{return console.log(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] \u76EE\u6807\u72B6\u6001: ${r}, \u8D85\u65F6: ${e/1e3}s`),await o.waitForLoadState(t,{timeout:e}),console.log(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] ${r} \u72B6\u6001\u5DF2\u5B8C\u6210\u3002`),!0}catch{return console.error(`[\u7B49\u5F85\u9875\u9762\u52A0\u8F7D] ${r} \u72B6\u6001\u5931\u8D25\u6216\u8D85\u65F6\u3002`),!1}}function X(o,t,e,r={}){return new Promise(async(i,s)=>{let{frameAttachedTimeout:n=45e3,frameVisibleTimeout:c=1e4,frameBodyTimeout:a=15e3,frameInLocatorOptions:p={},waitForElementTimeout:l=15e3,timeout:u=2e3}=r;console.log(`[\u7B49\u5F85 ${String(t)} iframe \u5B8C\u5168\u52A0\u8F7D]`);try{console.log("\u7B49\u5F85 iframe \u5143\u7D20..."),await o.waitForSelector(String(t),{state:"attached",timeout:n}),console.log("\u7B49\u5F85 iframe \u53EF\u89C1..."),await o.waitForSelector(String(t),{state:"visible",timeout:c}),console.log("\u2705 iframe \u53EF\u89C1");let m=o.frameLocator(String(t));await m.locator("body").waitFor({state:"attached",timeout:a}),console.log("\u2705 iframe \u5185\u5BB9\u5DF2\u52A0\u8F7D"),console.log(`[\u7B49\u5F85\u6307\u5B9A\u5143\u7D20\u53EF\u89C1] ${String(e)}`),await m.locator(e,p).waitFor({timeout:l}),console.log("[\u7B49\u5F85\u5B8C\u5168\u52A0\u8F7D]"),await o.waitForTimeout(u),i(m)}catch(m){s(m)}})}function W(o,t={}){return he(async e=>{let r=Date.now();for(;e.signal.aborted===!1&&Date.now()-r<(t.timeout||3e4);){if(await o.isVisible().catch(()=>!1))return o;await D(100)}throw new Error("waitForAbort \u8D85\u65F6")})}import{rInt as $}from"@tocha688/utils";async function q(o,t,e,r,i){if(typeof e=="string"&&(e=o.locator(e)),!_(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{clear:s=!0,delay:n={min:50,max:150},retries:c=3,...a}=i||{};if(await e.waitFor({state:"visible",...a}),await e.waitFor({state:"attached",...a}),await y(o,t,e,a),await D(50,100),s){let l=await e.inputValue().catch(()=>"");l&&l.length>0&&(await e.click({clickCount:3}),await D(20,50),await o.keyboard.press("Delete"),await D(20,50))}let p=k(r,5);for(let l=0;l<p.length;l++){let u=p[l];if(!await O(e)){await y(o,t,e,a);let h=await e.inputValue().catch(()=>"");h&&h.length>0&&await o.keyboard.press("End"),await D(30,60)}u&&await e.pressSequentially(u,{delay:$(n.min,n.max)}),l<p.length-1&&await D(50,150)}await D(100,200),await e.blur()}async function j(o,t,e,r,i){if(typeof e=="string"&&(e=o.locator(e)),!_(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{clear:s=!0,delay:n={min:50,max:150},retries:c=3,...a}=i||{};if(await e.waitFor({state:"visible",...a}),await e.waitFor({state:"attached",...a}),await y(o,t,e,a),await D(50,100),s){let l=await e.inputValue().catch(()=>"");l&&l.length>0&&(await e.click({clickCount:3}),await D(20,50),await o.keyboard.press("Delete"),await D(20,50))}let p=k(r,5);for(let l=0;l<p.length;l++){let u=p[l];u&&await e.pressSequentially(u,{delay:$(n.min,n.max)}),l<p.length-1&&await D(50,150)}await D(100,200),await e.blur()}async function z(o,t,e,r,i){if(typeof e=="string"&&(e=o.locator(e)),!_(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{retries:s=3,verify:n=!0,...c}=i||{};await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c});try{let p=await e.inputValue(),l=typeof r=="string"?r:Array.isArray(r)?r[0]?.toString():r?.toString();if(p===l)return}catch(p){console.warn(`\u83B7\u53D6\u5F53\u524D\u9009\u62E9\u503C\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await y(o,t,e,c),await D(50,100),await e.selectOption(r,c),await D(100,200),n){let p=await e.inputValue(),l=typeof r=="string"?r:Array.isArray(r)?r[0]?.toString():r?.toString();if(p!==l)throw new Error(`\u9009\u62E9\u9A8C\u8BC1\u5931\u8D25: \u671F\u671B"${l}", \u5B9E\u9645"${p}"`)}await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u9009\u62E9\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}async function J(o,t,e,r){if(typeof e=="string"&&(e=o.locator(e)),!_(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{force:i=!1,retries:s=3,verify:n=!0,...c}=r||{};if(await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c}),!i)try{if(await e.isChecked())return}catch(p){console.warn(`\u68C0\u67E5\u52FE\u9009\u72B6\u6001\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await y(o,t,e,c),await D(50,100),await e.check({force:i,...c}),await D(100,200),n&&!await e.isChecked())throw new Error("\u52FE\u9009\u9A8C\u8BC1\u5931\u8D25: \u5143\u7D20\u672A\u88AB\u6210\u529F\u52FE\u9009");await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u52FE\u9009\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}async function K(o,t,e,r){if(typeof e=="string"&&(e=o.locator(e)),!_(e))throw new Error("locator \u7C7B\u578B\u9519\u8BEF");let{force:i=!1,retries:s=3,verify:n=!0,...c}=r||{};if(await e.waitFor({state:"visible",...c}),await e.waitFor({state:"attached",...c}),!i)try{if(!await e.isChecked())return}catch(p){console.warn(`\u68C0\u67E5\u52FE\u9009\u72B6\u6001\u5931\u8D25: ${p}`)}let a=0;for(;a<s;)try{if(await y(o,t,e,c),await D(50,100),await e.uncheck({force:i,...c}),await D(100,200),n&&await e.isChecked())throw new Error("\u53D6\u6D88\u52FE\u9009\u9A8C\u8BC1\u5931\u8D25: \u5143\u7D20\u4ECD\u7136\u88AB\u52FE\u9009");await e.blur();return}catch(p){if(a++,a>=s)throw new Error(`\u53D6\u6D88\u52FE\u9009\u64CD\u4F5C\u5931\u8D25\uFF0C\u5DF2\u91CD\u8BD5${s}\u6B21: ${p}`);await D(200,400)}}function Y(o,t,e,r={}){let{interval:i=1e3,debug:s=!1}=r,n=[],c=!0,a=u=>{let m=u.url();(t instanceof RegExp?t.test(m):m.includes(t))&&(s&&console.log(`[Collector] \u6355\u83B7\u5230\u76EE\u6807\u8BF7\u6C42: ${m}`),n.push(u))};o.on("request",a);let p=setInterval(async()=>{if(c)for(s&&console.log(`[Poller] \u8F6E\u8BE2\u68C0\u67E5\u4E2D... \u5F53\u524D\u961F\u5217\u79EF\u538B: ${n.length}`);n.length>0;){let u=n.shift();if(u)if(e)await e(u);else{let m=`[Error] \u81F4\u547D\u9519\u8BEF: \u68C0\u6D4B\u5230\u88AB\u7981\u6B62\u7684\u8BF7\u6C42/\u672A\u5904\u7406\u7684\u8BF7\u6C42\u53D1\u9001! URL: ${u.url()}`;console.error(m),l()}}},i),l=()=>{c&&(c=!1,clearInterval(p),o.off("request",a),s&&console.log("[Poller] \u76D1\u542C\u5DF2\u505C\u6B62"))};return{stop:l}}function Q(o,t,e,r={}){let{interval:i=1e3,debug:s=!1}=r,n=!0,c=!1;s&&console.log(`[ElementMonitor] \u5F00\u59CB\u76D1\u542C\u5143\u7D20: "${t}"`);let a=setInterval(async()=>{if(!(!n||c))try{if(o.isClosed()){p();return}if(await o.isVisible(t))if(s&&console.log(`[ElementMonitor] \u53D1\u73B0\u76EE\u6807\u5143\u7D20: "${t}"`),c=!0,e)try{await e(o.locator(t))}catch(u){console.error(`[Callback Error] \u5904\u7406\u5143\u7D20 "${t}" \u56DE\u8C03\u5931\u8D25:`,u)}finally{c=!1}else{let u=`[Error] \u81F4\u547D\u9519\u8BEF: \u9875\u9762\u51FA\u73B0\u4E86\u4E0D\u8BE5\u51FA\u73B0\u7684\u5143\u7D20! Selector: "${t}"`;console.error(u),p()}}catch(l){s&&console.warn("[ElementMonitor] \u8F6E\u8BE2\u68C0\u67E5\u5F02\u5E38:",l)}},i),p=()=>{n&&(n=!1,clearInterval(a),s&&console.log(`[ElementMonitor] \u505C\u6B62\u76D1\u542C\u5143\u7D20: "${t}"`))};return{stop:p}}import{rInt as x,sleep as Z}from"@tocha688/utils";async function ee(o,t,e){let r=0,i=t+x(-100,100);if(console.log(`\u5F00\u59CB\u6A21\u62DF\u6EDA\u52A8\uFF0C\u76EE\u6807\u8DDD\u79BB: ${i}px`),e){let n=await e.boundingBox();if(n){let c=n.x+n.width/2+x(-10,10),a=n.y+n.height/2+x(-10,10);await o.mouse.move(c,a)}else console.warn("Target locator provided but element is not visible/present. Falling back to global scroll.")}let s=async n=>{await o.mouse.wheel(0,n),!e&&Math.random()<.3&&await o.mouse.move(x(100,500),x(100,500))};for(;r<i;){let n=x(50,150);r+n>i&&(n=i-r),await s(n),r+=n,Math.random()<.1?await Z(x(500,800)):await Z(x(30,100))}console.log("\u6EDA\u52A8\u5B8C\u6210")}var Ie="_ah_",L=class o{page;mouse;constructor(t){this.page=t,this.mouse=new B(t)}static create(t){let e=new o(t),r=Object.create(t);return Object.assign(r,t),Object.assign(r,e),["locator","getByRole","getByTestId","getByLabel","getByPlaceholder","getByText","getByAltText","getByTitle"].forEach(s=>{if(!t[s])return;let c=t[s].bind(t),a=Ie+s;r[a]=c,r[s]=function(...p){let l=r[a](...p);return l&&e.enhanceLocator(l)}}),r}enhanceLocator(t){let e=Object.create(t);return Object.assign(e,t),e._loc=t,e.click=this.click.bind(this,t),e.input=e.fill=this.input.bind(this,t),e.selectOption=e.select=this.select.bind(this,t),e.check=this.check.bind(this,t),e.uncheck=this.uncheck.bind(this,t),e}async click(t,e){return y(this.page,this.mouse,t,e)}async clickPoint(t,e,r){return U(this.mouse,t,e,r)}isLocator(t){return _(t)}async input(t,e,r){return q(this.page,this.mouse,t,e,r)}async inputFofce(t,e,r){return j(this.page,this.mouse,t,e,r)}async select(t,e,r){return z(this.page,this.mouse,t,e,r)}async check(t,e){return J(this.page,this.mouse,t,e)}async uncheck(t,e){return K(this.page,this.mouse,t,e)}async rWait(t=200,e=800){return D(t,e)}async safeWaitForLoadState(t="load",e=3e4){return H(this.page,t,e)}waitForIframeComplete(t,e,r={}){return X(this.page,t,e,r)}startRequestPolling(t,e,r={}){return Y(this.page,t,e,r)}startElementPolling(t,e,r,i={}){return Q(t,e,r,i)}waitForAbort(t,e={}){return W(t,e)}async humanScroll(t,e){return ee(this.page,t,e)}};import ve from"path";var Rt=ve.join(process.cwd(),"tmp","browser_cache");import Pe from"path";import{chromium as Le}from"patchright-core";function te(){let o=`${Date.now()}-${Math.random().toString(36).slice(2)}`,t=Pe.join(process.cwd(),"tmps",`brw-session-${o}`);return{sessionId:o,userDataDir:t}}async function I(o){return(await fetch(`http://127.0.0.1:${o}/json/version`).then(e=>e.json()))?.webSocketDebuggerUrl||""}async function M(o,t){let e=await o({...t}),r=await I(e.port);if(!r)throw e.close(),new Error("\u65E0\u6CD5\u83B7\u53D6\u6D4F\u89C8\u5668WebSocket URL");try{let i=await Le.connectOverCDP(r),s=i.contexts()[0]?.pages()?.[0]??await i.newPage();s.setDefaultNavigationTimeout(6e4),s.setDefaultTimeout(6e4);let n=new L(s);return i._hk_close=i.close,i.close=async function(){await i._hk_close(),await e.close()},{page:s,auto:n,brw:i}}catch(i){return console.log(i),await e.close(),await M(o,t)}}import{createPool as Ge}from"generic-pool";var re=class{constructor(t,e,r={}){this.startFn=t;this.opts=e;this.pool=Ge({create:async()=>await M(this.startFn,this.opts),destroy:async i=>{await i.brw.close()},validate:async i=>i.brw.isConnected()},{min:r.min??1,max:r.max??5,testOnBorrow:r.testOnBorrow??!0,idleTimeoutMillis:r.idleTimeoutMillis??3e4})}pool;async acquire(){let t=await this.pool.acquire();return{...t,release:async()=>{await this.pool.release(t)}}}async drain(){await this.pool.drain(),await this.pool.clear()}async use(t){let e=await this.acquire();try{return await t(e)}finally{await e.release()}}};import"patchright-core";import g from"fs";import Ee from"path";import{createHash as Ne}from"crypto";import{getAbsolutePath as Se}from"@tocha688/utils";function oe(o,t){let e=Ne("md5").update(o).digest("hex"),r=Ee.join(t,e),i=r+".meta.json";return{cacheFile:r,metaFile:i}}async function Zt(o,t=Se("./tmps/browser_cache")){g.existsSync(t)||g.mkdirSync(t,{recursive:!0}),console.log("\u542F\u7528\u6D4F\u89C8\u5668\u7F13\u5B58"),await o.route("**/*",async e=>{let r=e.request();if(r.method()!=="GET")return e.continue();let i=r.resourceType();if(["xhr","fetch","websocket","document"].includes(i))return e.continue();let s=r.url(),{cacheFile:n,metaFile:c}=oe(s,t);try{if(g.existsSync(n)&&g.existsSync(c)){let a=JSON.parse(g.readFileSync(c,"utf-8")),p=g.readFileSync(n);return Date.now()-a.timestamp>a.timeout?(g.unlinkSync(n),g.unlinkSync(c),e.continue()):e.fulfill({status:200,headers:a.headers,body:p,contentType:a.contentType})}}catch{}return e.continue()}),await o.on("response",async e=>{let r=e.request();if(r.method()!=="GET")return;let i=e.status();if(![200,201].includes(i))return;let s=e.url(),{cacheFile:n,metaFile:c}=oe(s,t);if(g.existsSync(n)&&g.existsSync(c))return;let a=e.headers();if((a["content-type"]||"").includes("text/plain")||s.includes(";"))return;let l=a["cache-control"]||"",u=a.pragma||"";if(l.includes("no-store")||u.includes("no-cache"))return;let m=r.resourceType();if(!(!(u||l)&&(["xhr","fetch","websocket","document"].includes(m)||new URL(s).searchParams.toString().length>0)))try{let h=await e.body();g.writeFileSync(n,h),g.writeFileSync(c,JSON.stringify({url:s,headers:a,contentType:a["content-type"],timestamp:Date.now(),timeout:parseInt(a["cache-control"]?.match(/max-age=(\d+)/)?.[1]||"99999999")*1e3}))}catch{}})}async function Fe(o,t,e){return await fetch(t.url(),{method:t.method(),body:t.postData(),headers:t.headers()}).then(async r=>o.fulfill({status:r.status,headers:Object.fromEntries(r.headers.entries()),body:Buffer.from(await r.arrayBuffer())})).catch(()=>o.abort())}async function rr(o){await o.route("**/*",async t=>{let e=t.request(),r=e.url(),i=e.resourceType();return["GET"].includes(e.method())?["xhr","fetch","websocket","document"].includes(i)||["script"].includes(i)&&r.includes("?")?await t.continue():await Fe(t,e,o):await t.continue()})}async function or(o){await o.route("**/*",async t=>{let e=t.request();if(e.method()!=="GET")return t.continue();let r=e.resourceType();return["xhr","fetch","websocket","document","script"].includes(r)?t.continue():t.abort()})}import*as ie from"chrome-launcher";import{chromium as Re}from"patchright-core";async function cr(o){let{chromePath:t,headless:e=!1,userDataDir:r}=o,i=["--disable-blink-features=AutomationControlled","--no-sandbox","--disable-setuid-sandbox"];e&&i.push("--headless");let s=await ie.launch({chromePath:t,chromeFlags:i,userDataDir:r}),n=await I(s.port);return{userDataDir:r||"",port:s.port,browser:s,wsUrl:n,close:async()=>await s.kill(),async mainPage(){let c=await Re.connectOverCDP(n),a=c.contexts()?.[0]??await c.newContext();return a?.pages()?.[0]??await a.newPage()}}}import b from"fs";import N from"path";import{faker as De}from"@faker-js/faker";function G(o){let t,e;t===void 0&&(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),e===void 0&&(e="hTy1bfRJz4nLPcBCO7WtmNIaGvVeul5Zo8kq32UxrYw_-0gsjp96SDFXQiEMKdHA");var r=t,i=e,s=Buffer.from(o).toString("base64").split(""),n="";return s.map((function(c){var a=r.indexOf(c);return n+=a<0?c:i.substr(a,1),c})),n}function se(o){let t,e;if(t===void 0&&(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),e===void 0&&(e="hTy1bfRJz4nLPcBCO7WtmNIaGvVeul5Zo8kq32UxrYw_-0gsjp96SDFXQiEMKdHA"),!o)return"";var r=t,i=e,s=o.split(""),n="";return s.map((function(c){var a=i.indexOf(c);return n+=a<0?c:r.substr(a,1),c})),Buffer.from(n,"base64").toString()}import ke from"font-list";import{rInt as ne}from"@tocha688/utils";var ae=["750 \xD7 1334","800 x 600","1024 x 600","1024 x 640","1024 x 768","1152 x 864","1280 x 720","1280 x 768","1280 x 800","1280 x 960","1280 x 1024","1360 x 768","808 \xD7 1792","828 \xD7 1792","1080 x 2340","1125 x 2436","1242 x 2208","1170 \xD7 2532","1284 x 2778","1366 x 768","1400 x 1050","1400 x 900","1440 x 900","1536 x 864","1600 x 900","1600 x 1200","1680 x 1050","1920 x 1080","1920 x 1200","2048 x 1152","2304 x 1440","2560 x 1440","2560 x 1600","2880 x 1800","4096 x 2304","5120 x 2880"],ce=["2","3","4","6","8","10","12","16","20","24","32","64"],fr=["2","4","6","8","16","32","64","128"],wr=[{name:"Google Inc. (AMD)",values:["ANGLE (AMD, RENOIR(renoir LLVM 15.0.7), OpenGL 4.6)"]},{name:"Google Inc. (Intel)",values:["ANGLE (Intel, Mesa Intel(R) Graphics (RPL-S), OpenGL 4.6)","ANGLE (Intel, Mesa Intel(R) Graphics (RPL-P), OpenGL 4.6)","ANGLE (Intel, Mesa Intel(R) Xe Graphics (TGL GT2), OpenGL 4.6)"]}],le=[{name:"Google Inc. (NVIDIA)",vendor:"nvidia",values:["ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 SUPER (0x000021C4) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6647)","ANGLE (NVIDIA, NVIDIA GeForce GTX 750 Ti (0x00001380) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6647)","ANGLE (NVIDIA, NVIDIA GeForce GTX 650 (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6140)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 Ti (0x00001C8C) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (NVIDIA, NVIDIA GeForce GT 635M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.13.6472)","ANGLE (NVIDIA, NVIDIA GeForce GT 710 (0x0000128B) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.3160)","ANGLE (NVIDIA, NVIDIA GeForce 410M (0x00001055) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6093)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1060 (0x00001C20) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5148)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 (0x00002184) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5751)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2070 SUPER (0x00001E84) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 750 Ti (0x00001380) Direct3D9Ex vs_3_0 ps_3_0, nvd3dumx.dll-26.21.14.4219)","ANGLE (NVIDIA, NVIDIA GeForce GT 730 (0x00001287) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 (0x00001F9D) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5751)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 (0x00001C91) Direct3D11 vs_5_0 ps_5_0, D3D11-22.21.13.8476)","ANGLE (NVIDIA, NVIDIA GeForce GTX 950 (0x00001402) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4187)","ANGLE (NVIDIA, NVIDIA GeForce GTX 960 (0x00001401) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce RTX 3070 (0x00002484) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.6611)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5256)","ANGLE (NVIDIA, NVIDIA GeForce GTX 660 (0x000011C0) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 970 (0x000013C2) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 (0x00001F9D) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5256)","ANGLE (NVIDIA, NVIDIA GeForce 205 (0x00002504) Direct3D11 vs_4_1 ps_4_1, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1070 (0x00001BA1) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA Quadro K620 (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1060 3GB (0x00001C02) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (NVIDIA, NVIDIA GeForce GT 635M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11-23.21.13.9124)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1050 (0x00001C91) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.3630)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 (0x00001F51) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4250)","ANGLE (NVIDIA, NVIDIA GeForce RTX 2060 SUPER (0x00001F47) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5167)","ANGLE (NVIDIA, NVIDIA Quadro P600 (0x00001CB2) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5239)","ANGLE (NVIDIA, NVIDIA Quadro M1000M (0x00002504) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 550 Ti (0x00001244) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce 210 (0x00000A65) Direct3D11 vs_4_0 ps_4_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1650 SUPER (0x00002187) Direct3D11 vs_5_0 ps_5_0, D3D11-26.21.14.4120)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1660 Ti (0x00002191) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GT 1030 (0x00001D01) Direct3D11 vs_5_0 ps_5_0, D3D11-27.21.14.5671)","ANGLE (NVIDIA, NVIDIA GeForce GTX 970 (0x000013C2) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (NVIDIA, NVIDIA GeForce GTX 1070 (0x00001BA1) Direct3D11 vs_5_0 ps_5_0, D3D11-23.21.13.8813)","ANGLE (NVIDIA, NVIDIA GeForce GT 730 (0x00001287) Direct3D11 vs_5_0 ps_5_0, D3D11-9.18.13.4411)"]},{name:"Google Inc. (AMD)",vendor:"amd",values:["ANGLE (AMD, AMD Radeon(TM) RX 560 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Mobile Graphics (0x000015DD) Direct3D9Ex vs_3_0 ps_3_0, D3D11)","ANGLE (AMD, Radeon RX RX550/550 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon R7 350 Series (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.15029.27017)","ANGLE (AMD, AMD Radeon(TM) R7 Graphics (0x0000130F) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1034.6)","ANGLE (AMD, Radeon RX 560 Series (0x000067EF) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.15029.27017)","ANGLE (AMD, AMD Radeon HD 7800 Series (0x00006819) Direct3D9Ex vs_3_0 ps_3_0, aticfx64.dll-26.20.15029.15007)","ANGLE (AMD, AMD Radeon RX 580 2048SP (0x00006FDF) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.15003.5017)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14501.18003)","ANGLE (AMD, AMD Radeon(TM) Graphics (0x0000164E) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14044.2001)","ANGLE (AMD, AMD Radeon Series (0x00001636) Direct3D9Ex vs_3_0 ps_3_0, aticfx32.dll-23.20.15002.11)","ANGLE (AMD, Radeon (TM) RX 470 Graphics (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.13031.18002)","ANGLE (AMD, AMD Radeon HD 6530D (0x00001636) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, Radeon RX 580 Series (0x000067DF) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.14534.2)","ANGLE (AMD, AMD Radeon(TM) RX Vega 10 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.14132.2002)","ANGLE (AMD, AMD Radeon R7 430 (0x00006611) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon (TM) R9 200 Series (0x00006811) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1034.6)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.11008.3003)","ANGLE (AMD, AMD Radeon(TM) RX Vega 10 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1028.1)","ANGLE (AMD, AMD Radeon(TM) Graphics (0x0000164E) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.1020.2002)","ANGLE (AMD, AMD Radeon(TM) Vega 8 Graphics (0x000015DD) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (AMD, AMD Radeon R7 200 Series (0x00006658) Direct3D11 vs_5_0 ps_5_0, D3D11)"]},{name:"Google Inc. (Intel)",vendor:"Intel",values:["ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.100.6617)","ANGLE (Intel, Intel(R) UHD Graphics 620 (0x00003EA0) Direct3D11 vs_5_0 ps_5_0, D3D11-24.20.100.6346)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.100.7637)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.8682)","ANGLE (Intel, Intel(R) HD Graphics Family (0x00000A16) Direct3D9Ex vs_3_0 ps_3_0, igdumdim64.dll-10.18.10.3907)","ANGLE (Intel, Intel(R) HD Graphics 4000 (0x00000162) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.4252)","ANGLE (Intel, Intel(R) HD Graphics 530 (0x0000191B) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.4364)","ANGLE (Intel, Intel(R) UHD Graphics 620 (0x00003EA0) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.9126)","ANGLE (Intel, Intel(R) UHD Graphics (0x00009BA4) Direct3D11 vs_5_0 ps_5_0, D3D11-26.20.100.7985)","ANGLE (Intel, Intel(R) HD Graphics Family (0x00000A16) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.5058)","ANGLE (Intel, Intel(R) UHD Graphics 610 (0x00003EA1) Direct3D11 vs_5_0 ps_5_0, D3D11-25.20.100.6471)","ANGLE (Intel, Intel(R) HD Graphics 4600 (0x00000416) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.14.5067)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5100)","ANGLE (Intel, Intel(R) UHD Graphics 630 (0x00003E98) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.9466)","ANGLE (Intel, Intel(R) HD Graphics 4400 (0x0000041E) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.3412)","ANGLE (Intel, Intel(R) Iris(TM) Graphics 6100 (0x00007DD5) Direct3D11 vs_5_0 ps_5_0, D3D11)","ANGLE (Intel, Intel(R) Iris(R) Plus Graphics (0x00008A5A) Direct3D11 vs_5_0 ps_5_0, D3D11-27.20.100.8853)","ANGLE (Intel, Intel(R) HD Graphics 520 (0x00001921) Direct3D11 vs_5_0 ps_5_0, D3D11-21.20.16.4727)","ANGLE (Intel, Intel(R) Iris(R) Plus Graphics (0x00008A5A) Direct3D9Ex vs_3_0 ps_3_0, D3D9Ex)","ANGLE (Intel, Intel(R) HD Graphics (0x000022B0) Direct3D11 vs_5_0 ps_5_0, D3D11-10.18.10.5059)","ANGLE (Intel, Intel(R) HD Graphics 5300 (0x00007DD5) Direct3D11 vs_5_0 ps_5_0, D3D11-20.19.15.4531)","ANGLE (Intel, Intel(R) HD Graphics 4000 (0x00000162) Direct3D9Ex vs_3_0 ps_3_0, igdumd64.dll-9.17.10.2849)"]}];async function pe(){let t=(await ke.getFonts()).filter(i=>!/[\u4e00-\u9fa5]/.test(i)),e=ne(5,Math.min(50,t.length)),r=[...t];for(let i=r.length-1;i>0;i--){let s=ne(0,i),n=r[i];r[i]=r[s],r[s]=n}return r.slice(0,e)}import{checkAutoProxy as Ve,rArrItem as v,rInt as Ce,rAutoDigitInt as P,getIpInfo as Be}from"@tocha688/utils";import Me from"portfinder";import T from"fs";import*as ue from"chrome-launcher";import{tryCatch as V,tryLoop as me}from"@tocha688/utils";import{chromium as Te}from"patchright-core";async function E(o,t){o.userDataDir=o.userDataDir||te().userDataDir;let{userDataDir:e}=o;T.mkdirSync(e,{recursive:!0});let r;try{let i=await Me.getPortPromise({port:41e3,stopPort:49999});r=await t.prepare(e,i);let s=[`--user-data-dir=${e}`,`--remote-debugging-port=${i}`,"--remote-debugging-address=0.0.0.0",...r.args];o.headless!==!1&&!s.some(a=>a.startsWith("--headless"))&&s.push("--headless");let n=await ue.launch({userDataDir:e,port:i,chromePath:o.chromePath,chromeFlags:s,startingUrl:r.startingUrl||"about:blank"}),c=await I(n.port);return{userDataDir:e,port:n.port,browser:n,wsUrl:c,close:async()=>{await V(async()=>await n.kill()),r?.cleanup&&await V(r.cleanup),await me(async()=>T.rmSync(e,{recursive:!0,force:!0}))},async mainPage(){let a=await Te.connectOverCDP(c),p=a.contexts()?.[0]??await a.newContext();return p?.pages()?.[0]??await p.newPage()}}}catch(i){throw await me(async()=>T.rmSync(e,{recursive:!0,force:!0})),r?.cleanup&&await V(r.cleanup),i}}async function Cr(o){return E(o,{prepare:async(t,e)=>{let r=N.join(t,"webgl.json"),i=N.join(t,"dynamic.config"),s=N.join(t,"static.config"),n=N.join(t,"params.config"),c,a;if(b.existsSync(n))c=b.readFileSync(n,"utf-8"),a=JSON.parse(se(c)).ScreenSize;else{let l={},u;o.proxy?(l=await Ve(o.proxy),u=new URL(l.proxy)):l=await Be(l.proxy);let m={fp:Ce(1e5,999999),geop:l?.latitude?l?.latitude+","+l?.longitude:"",device_name:"PC"+De.string.alphanumeric(8).toUpperCase(),timezone:l?.timezone||l?.timeZone||"America/Los_Angeles",proxy:{protocol:u?.protocol.replace(":","")||"http",host:u?.hostname||"127.0.0.1",port:u?.port||"8080",username:u?.username||"",password:u?.password||""},mac:De.internet.mac(),scanPorts:"",screenSize:v(ae),langs:l?.languages??"en-US,en"},h=v(le),S={UNMASKED_VENDOR_WEBGL:h.name,UNMASKED_RENDERER_WEBGL:v(h.values),GPUAdapterInfo:{vendor:h.vendor,architecture:"pascal"},SUPPORTED_EXTENSIONS:[]},de={BlockList:{Version:"1743148877",Domains:[]},StrongBlockList:{Version:"3",Domains:[]},TimeZone:m.timezone,Geoposition:m.geop},w={CookiesExportPath:"",SecurePreferenceSync:!0,PasswordExportPath:"",PasswordImportPath:"",RestoreLastSession:!0,BlockPage:"NDA0",FoceSafeBrowsing:!0,ExtensionSetting:[],DisCanvasUrl:"",MaxTouchPoints:0,MediaDevices:[{kind:"audioinput",label:"Microphone Array (Realtek(R) Audio)"},{kind:"videoinput",label:"Integrated Camera (98da:3959)"},{kind:"audiooutput",label:"Speakers (Realtek(R) Audio)"}],AudioFp:P(980,m.fp),WebGLMark:"5001",StartTime:Math.floor(Date.now()/1e3),GeolocationSetting:"ask",FlashPluginSetting:"block",Platform:"Win32",ScreenSize:m.screenSize,DisableBackgroundMode:!0,DisableWebRTC:!0,HardwareConcurrency:v(ce),DeviceMemory:v([4,8]),LoadExtensionErrorBox:!1,ClientRectFp:P("5001",m.fp).toString(),ForceProcessExit:!0,ProxyUser:m.proxy.username,ProxyPassword:m.proxy.password,Langs:m.langs,AcceptLang:m.langs?m.langs+",q=0.9":"en-US,en;q=0.9",DisabledFonts:(await pe()).join(",")};b.writeFileSync(r,JSON.stringify(S)),b.writeFileSync(i,G(JSON.stringify(de))),b.writeFileSync(s,G(JSON.stringify(w))),c=G(JSON.stringify({UserId:"1",CanvasMark:P("7949",m.fp).toString(),DisableContainer:!0,WebGLFP:r,AudioFp:w.AudioFp,WebGLMark:w.WebGLMark,StartTime:w.StartTime,AllowScanPorts:m.scanPorts,GeolocationSetting:w.GeolocationSetting,FlashPluginSetting:w.FlashPluginSetting,Platform:w.Platform,ScreenSize:w.ScreenSize,DisableBackgroundMode:w.DisableBackgroundMode,DisableWebRTC:w.DisableWebRTC,HardwareConcurrency:w.HardwareConcurrency,DeviceMemory:w.DeviceMemory,LoadExtensionErrorBox:w.LoadExtensionErrorBox,ClientRectFp:w.ClientRectFp,CanvasMarkEx:P("7949",m.fp).toString(),WebGLMarkEx:P("5001",m.fp).toString(),command_line:{"do-not-de-elevate":""},ProxyChain:[{scheme:m.proxy.protocol,host:m.proxy.host,port:m.proxy.port,account:m.proxy.username,password:m.proxy.password}],ForceProcessExit:w.ForceProcessExit,ProxyUser:w.ProxyUser,ProxyPassword:w.ProxyPassword,Langs:w.Langs,AcceptLang:w.AcceptLang,TimeZone:m.timezone,Geoposition:m.geop,DynamicConfig:i,StaticConfig:s})),b.writeFileSync(n,c),a=w.ScreenSize}return{args:["--disable-background-networking","--disable-client-side-phishing-detection","--disable-default-apps","--disable-hang-monitor","--disable-popup-blocking","--disable-prompt-on-repost","--disable-sync","--metrics-recording-only","--no-first-run","--safebrowsing-disable-auto-update","--password-store=basic","--no-service-autorun","--disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes","--force-color-profile=srgb","--use-mock-keychain","--export-tagged-pdf","--no-default-browser-check","--window-position=0,0","--disable-background-mode","--ash-host-window-bounds="+a,"--window-size="+a,"--disable-renderer-accessibility","--disable-legacy-window","--fake-variations-channel=stable","--variations-server-url=https://clientservices.googleapis.com/chrome-variations/seed","--component-updater=initial-delay=6e5","--lang=en-US","--enable-features=NetworkService,NetworkServiceInProcess,LoadCryptoTokenExtension,PermuteTLSExtensions","--enable-blink-features=IdleDetection,Fledge","--extended-parameters="+c,"--flag-switches-begin","--flag-switches-end","--load-extension=","--no-sandbox"],startingUrl:"https://ipapi.co/json/"}}})}import{faker as Oe}from"@faker-js/faker";import{getIpInfo as Ue,startProxyServer as He}from"@tocha688/utils";import C from"fs";import Xe from"path";async function We(o){return E(o,{prepare:async(t,e)=>{let r;o.proxy&&(r=await He(o.proxy),console.log(`Started proxy server on port ${r.port}`));let i=r?.ipinfo;i&&(i=await Ue(i.proxy));let s=Xe.join(t,"fingerprint.config"),n;C.existsSync(s)?n=C.readFileSync(s,"utf-8"):(n=Oe.number.int({min:1e7,max:99999999}).toString(),C.writeFileSync(s,n));let c=["--allow-pre-commit-input","--disable-background-networking","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad","--disable-client-side-phishing-detection","--disable-component-extensions-with-background-pages","--disable-crash-reporter","--disable-default-apps","--disable-dev-shm-usage","--disable-hang-monitor","--disable-infobars","--disable-ipc-flooding-protection","--disable-popup-blocking","--disable-prompt-on-repost","--disable-renderer-backgrounding","--disable-search-engine-choice-screen","--disable-sync","--export-tagged-pdf","--force-color-profile=srgb","--generate-pdf-document-outline","--metrics-recording-only","--no-first-run","--password-store=basic","--use-mock-keychain","--disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes","--enable-features=PdfOopif","--fingerprints="+n,"--window-size=1280,720","--window-position=0,0","--no-sandbox","--ignore-certificate-errors","--notice-number=1","--ignores=tls","--enable-logging","--timezone="+(i?.timezone??"America/Los_Angeles"),"--lang=en-US"];return r&&r.port&&c.push(`--proxy-server=http://127.0.0.1:${r.port}`),{args:c,startingUrl:"https://ipapi.co/json/",cleanup:async()=>{r&&await r.server.close(!0)}}}})}async function qr(o){return We(o)}import"chrome-launcher";import"proxy-chain";export{Cr as AdsBrowserStartMain,L as AutoHelper,Rt as BrowserCachePath,re as BrowserPool,ce as Cpus,R as HumanMouse,wr as LinuxWebGL,fr as Memorys,qr as OKBrowserCreate,We as OKBrowserStartMain,ae as PcScreen,le as WindowsWebGL,M as createBrowser,Fe as fetchResource,I as getBrowserWebSocketUrl,O as isElementFocused,_ as isLocator,E as launchBrowserBase,te as makeUniqueBrowserConfig,pe as rSysFonts,or as routeAssetsAbort,Zt as routeAssetsCache,rr as routeAssetsLocal,k as splitTextIntoChunks,cr as startLocalBrowser};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tocha688/browser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "dist/index.cjs",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"portfinder": "^1.0.38",
|
|
35
35
|
"proxy-chain": "^2.7.1",
|
|
36
36
|
"undici": "^7.18.2",
|
|
37
|
-
"@tocha688/utils": "
|
|
37
|
+
"@tocha688/utils": "1.0.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup"
|
package/src/network/cache.ts
CHANGED
|
@@ -7,6 +7,7 @@ import fs from "fs";
|
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { createHash } from "crypto";
|
|
9
9
|
import { BrowserCachePath } from "../core/config";
|
|
10
|
+
import { getAbsolutePath } from "@tocha688/utils";
|
|
10
11
|
|
|
11
12
|
function getCachePath(url: string, cachePath: string) {
|
|
12
13
|
const hash = createHash("md5").update(url).digest("hex");
|
|
@@ -15,8 +16,8 @@ function getCachePath(url: string, cachePath: string) {
|
|
|
15
16
|
return { cacheFile, metaFile }
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
/** 缓存浏览器到目录 ./
|
|
19
|
-
export async function routeAssetsCache(page: Page, cachePath: string) {
|
|
19
|
+
/** 缓存浏览器到目录 ./tmps/browser_cache */
|
|
20
|
+
export async function routeAssetsCache(page: Page, cachePath: string = getAbsolutePath("./tmps/browser_cache")) {
|
|
20
21
|
// 确保缓存目录存在
|
|
21
22
|
if (!fs.existsSync(cachePath)) {
|
|
22
23
|
fs.mkdirSync(cachePath, { recursive: true });
|
package/src/providers/base.ts
CHANGED
|
@@ -21,7 +21,8 @@ export async function launchBrowserBase(
|
|
|
21
21
|
opts: BrowserStartOptions,
|
|
22
22
|
config: BrowserLaunchConfig
|
|
23
23
|
): Promise<BrowserResult> {
|
|
24
|
-
|
|
24
|
+
opts.userDataDir = opts.userDataDir || makeUniqueBrowserConfig().userDataDir;
|
|
25
|
+
const { userDataDir } = opts;
|
|
25
26
|
// Ensure userDataDir exists
|
|
26
27
|
fs.mkdirSync(userDataDir, { recursive: true });
|
|
27
28
|
|