@rent-scraper/browser-server 1.0.34 → 1.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{h as r}from"../shared/browser-server.BZvS6Tr9.mjs";import"express";import"puppeteer";import"fs/promises";import"child_process";import"os";import"path";import"@rent-scraper/utils/config";import"@rent-scraper/utils";r();
2
+ import{h as r}from"../shared/browser-server.AqQl6-Nm.mjs";import"express";import"puppeteer";import"fs/promises";import"child_process";import"os";import"path";import"@rent-scraper/utils/config";import"@rent-scraper/utils";r();
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export{c as closeBrowser,g as getBrowser,a as getBrowserStatus,d as getRedfinCookie,b as getZillowCookie,l as launchBrowser,o as openBrowser,r as refreshZillowCookie,h as runBrowserServer,e as saveRedfinCookie,f as saveZillowCookie,s as shutdownBrowser,w as waitForBrowser}from"./shared/browser-server.BZvS6Tr9.mjs";import{confirm as r,isCancel as a,cancel as s,outro as i}from"@clack/prompts";import{setTimeout as o}from"node:timers/promises";import"express";import"puppeteer";import"fs/promises";import"child_process";import"os";import"path";import"@rent-scraper/utils/config";import"@rent-scraper/utils";async function t(){const e=await r({message:"We need to launch your browser to continue",active:"OK",inactive:"Cancel"});if(a(e)||!e)return s("Create config canceled. Please try again."),process.exit(1);await o(1e3),i("Browser Launching..."),await o(1e3)}export{t as runConfirmBrowserLaunch};
1
+ export{c as closeBrowser,g as getBrowser,a as getBrowserStatus,d as getRedfinCookie,b as getZillowCookie,l as launchBrowser,o as openBrowser,r as refreshZillowCookie,h as runBrowserServer,e as saveRedfinCookie,f as saveZillowCookie,s as shutdownBrowser,w as waitForBrowser}from"./shared/browser-server.AqQl6-Nm.mjs";import{confirm as r,isCancel as a,cancel as s,outro as i}from"@clack/prompts";import{setTimeout as o}from"node:timers/promises";import"express";import"puppeteer";import"fs/promises";import"child_process";import"os";import"path";import"@rent-scraper/utils/config";import"@rent-scraper/utils";async function t(){const e=await r({message:"We need to launch your browser to continue",active:"OK",inactive:"Cancel"});if(a(e)||!e)return s("Create config canceled. Please try again."),process.exit(1);await o(1e3),i("Browser Launching..."),await o(1e3)}export{t as runConfirmBrowserLaunch};
@@ -0,0 +1 @@
1
+ import q from"express";import E from"puppeteer";import{mkdtemp as X,access as Y}from"fs/promises";import{exec as k}from"child_process";import{tmpdir as ee}from"os";import te from"path";import{checkForConfigFile as oe,waitForConfigFile as ne,getValueFromConfigFile as ae,updateConfigFile as M}from"@rent-scraper/utils/config";import{parseError as L}from"@rent-scraper/utils";const j={darwin:["/Applications/Brave Browser.app/Contents/MacOS/Brave Browser","/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Chromium.app/Contents/MacOS/Chromium","/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"],linux:["/usr/bin/brave-browser","/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/usr/bin/chromium-browser","/usr/bin/chromium","/snap/bin/chromium"],win32:["C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe","C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"]},H=async()=>{const e=j[process.platform]??[];for(const t of e)try{return await Y(t),t}catch{}return null},V="http://127.0.0.1:9222/json/version",se=async(e=15e3)=>{const t=Date.now();for(;Date.now()-t<e;)try{await E.connect({browserURL:V});return}catch{await new Promise(c=>setTimeout(c,500))}throw new Error("timed out waiting for browser")},$=async()=>{try{return await E.connect({browserURL:V})}catch{return null}},S=async()=>{const e=await(await $())?.pages();e&&(process.platform==="linux"&&e.length>0?(await e[0].goto("about:blank"),await Promise.all(e.slice(1).map(t=>t.close()))):await Promise.all(e.map(t=>t.close())))},N=async(e="zillow")=>{if(await $())return{status:"already launched"};await oe(e)||await ne(e);const t=await X(te.join(ee(),"chrome-remote-")),c=await ae(e,"browser"),a=c?(j[process.platform]??[]).find(s=>s.toLowerCase().includes(c.toLowerCase()))??await H():await H();if(console.log(`launching browser: ${a??"bundled chromium"}`),a)k(`"${a}" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir="${t}"`,s=>{s&&console.error(`Error: ${s.message}`)});else{const s=["--remote-debugging-port=9222","--no-first-run","--no-default-browser-check",`--user-data-dir=${t}`,...process.platform==="linux"?["--no-sandbox","--disable-setuid-sandbox"]:[]];await E.launch({headless:!1,args:s,dumpio:!1})}return{status:"launched"}},W=async()=>{const e=await $();if(e){const t=(await e.pages())?.[0];return t?(await t.title()).includes("denied")?{status:"captcha"}:{status:"navigated"}:{status:"navigated"}}else return{status:"not connected"}},_=async e=>{const t=await $();if(t){const c=e,a=(await t.pages())?.[0]??await t.newPage();return(await a.title()).includes("denied")?{status:"captcha"}:(await a.goto(c,{waitUntil:"load"}),(await a.title()).includes("denied")?{status:"captcha"}:{status:"navigated"})}else return{status:"not connected"}},U=async()=>{const e=await $();if(e){try{await(await e.target().createCDPSession()).send("Browser.close")}catch{await e.disconnect()}return{status:"closed"}}else return{status:"not connected"}},G="http://127.0.0.1:9222/json/version",A=async(e=0)=>{const t=await E.connect({browserURL:G});e===0&&await _("https://www.zillow.com/homes/for_rent/");const c=await t.cookies(),[a]=c.filter(n=>n.name==="_pxvid"),[s]=c.filter(n=>n.name==="_px3");return a?(await S(),[a,s].filter(Boolean).map(n=>`${n.name}=${n.value}`).join("; ")):(console.log("refetching zillow cookie"),await new Promise(n=>setTimeout(n,2e3)),await A(e+1))},I=async(e=0)=>{const t=await E.connect({browserURL:G});e===0&&(await _("https://www.redfin.com"),await new Promise(n=>setTimeout(n,3e3)));const c=await t.pages(),a=c?.[0]?await c[0].title():"",s=(await t.cookies()).filter(n=>n.domain.includes("redfin.com"));return s.some(n=>n.name==="aws-waf-token")&&a.includes("Redfin")?(await S(),s.map(n=>`${n.name}=${n.value}`).join("; ")):(console.log("refetching redfin cookie"),await new Promise(n=>setTimeout(n,2e3)),await I(e+1))},Z=async()=>{try{const e=await I();e&&await M("redfin",{redfinCookie:e})}catch(e){const{status:t,message:c}=L(e);console.error(t,c)}},J=async()=>{try{const e=await(await E.connect({browserURL:G})).cookies(),[t]=e.filter(a=>a.name==="_pxvid"),[c]=e.filter(a=>a.name==="_px3");if(t){const a=[t,c].filter(Boolean).map(s=>`${s.name}=${s.value}`).join("; ");return await M("zillow",{zillowCookie:a}),a}}catch(e){const{status:t,message:c}=L(e);console.error(t,c)}},D=async()=>{try{const e=await A();e&&await M("zillow",{zillowCookie:e})}catch(e){const{status:t,message:c}=L(e);console.error(t,c)}};function re(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var x,Q;function ie(){if(Q)return x;Q=1;function e(a,s){var n=a;s.slice(0,-1).forEach(function(w){n=n[w]||{}});var p=s[s.length-1];return p in n}function t(a){return typeof a=="number"||/^0x[0-9a-f]+$/i.test(a)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(a)}function c(a,s){return s==="constructor"&&typeof a[s]=="function"||s==="__proto__"}return x=function(a,s){s||(s={});var n={bools:{},strings:{},unknownFn:null};typeof s.unknown=="function"&&(n.unknownFn=s.unknown),typeof s.boolean=="boolean"&&s.boolean?n.allBools=!0:[].concat(s.boolean).filter(Boolean).forEach(function(i){n.bools[i]=!0});var p={};function w(i){return p[i].some(function(d){return n.bools[d]})}Object.keys(s.alias||{}).forEach(function(i){p[i]=[].concat(s.alias[i]),p[i].forEach(function(d){p[d]=[i].concat(p[i].filter(function(C){return d!==C}))})}),[].concat(s.string).filter(Boolean).forEach(function(i){n.strings[i]=!0,p[i]&&[].concat(p[i]).forEach(function(d){n.strings[d]=!0})});var r=s.default||{},o={_:[]};function T(i,d){return n.allBools&&/^--[^=]+$/.test(d)||n.strings[i]||n.bools[i]||p[i]}function P(i,d,C){for(var u=i,F=0;F<d.length-1;F++){var y=d[F];if(c(u,y))return;u[y]===void 0&&(u[y]={}),(u[y]===Object.prototype||u[y]===Number.prototype||u[y]===String.prototype)&&(u[y]={}),u[y]===Array.prototype&&(u[y]=[]),u=u[y]}var B=d[d.length-1];c(u,B)||((u===Object.prototype||u===Number.prototype||u===String.prototype)&&(u={}),u===Array.prototype&&(u=[]),u[B]===void 0||n.bools[B]||typeof u[B]=="boolean"?u[B]=C:Array.isArray(u[B])?u[B].push(C):u[B]=[u[B],C])}function h(i,d,C){if(!(C&&n.unknownFn&&!T(i,C)&&n.unknownFn(C)===!1)){var u=!n.strings[i]&&t(d)?Number(d):d;P(o,i.split("."),u),(p[i]||[]).forEach(function(F){P(o,F.split("."),u)})}}Object.keys(n.bools).forEach(function(i){h(i,r[i]===void 0?!1:r[i])});var z=[];a.indexOf("--")!==-1&&(z=a.slice(a.indexOf("--")+1),a=a.slice(0,a.indexOf("--")));for(var m=0;m<a.length;m++){var l=a[m],f,v;if(/^--.+=/.test(l)){var K=l.match(/^--([^=]+)=([\s\S]*)$/);f=K[1];var R=K[2];n.bools[f]&&(R=R!=="false"),h(f,R,l)}else if(/^--no-.+/.test(l))f=l.match(/^--no-(.+)/)[1],h(f,!1,l);else if(/^--.+/.test(l))f=l.match(/^--(.+)/)[1],v=a[m+1],v!==void 0&&!/^(-|--)[^-]/.test(v)&&!n.bools[f]&&!n.allBools&&(!p[f]||!w(f))?(h(f,v,l),m+=1):/^(true|false)$/.test(v)?(h(f,v==="true",l),m+=1):h(f,n.strings[f]?"":!0,l);else if(/^-[^-]+/.test(l)){for(var g=l.slice(1,-1).split(""),O=!1,b=0;b<g.length;b++){if(v=l.slice(b+2),v==="-"){h(g[b],v,l);continue}if(/[A-Za-z]/.test(g[b])&&v[0]==="="){h(g[b],v.slice(1),l),O=!0;break}if(/[A-Za-z]/.test(g[b])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(v)){h(g[b],v,l),O=!0;break}if(g[b+1]&&g[b+1].match(/\W/)){h(g[b],l.slice(b+2),l),O=!0;break}else h(g[b],n.strings[g[b]]?"":!0,l)}f=l.slice(-1)[0],!O&&f!=="-"&&(a[m+1]&&!/^(-|--)[^-]/.test(a[m+1])&&!n.bools[f]&&(!p[f]||!w(f))?(h(f,a[m+1],l),m+=1):a[m+1]&&/^(true|false)$/.test(a[m+1])?(h(f,a[m+1]==="true",l),m+=1):h(f,n.strings[f]?"":!0,l))}else if((!n.unknownFn||n.unknownFn(l)!==!1)&&o._.push(n.strings._||!t(l)?l:Number(l)),s.stopEarly){o._.push.apply(o._,a.slice(m+1));break}}return Object.keys(r).forEach(function(i){e(o,i.split("."))||(P(o,i.split("."),r[i]),(p[i]||[]).forEach(function(d){P(o,d.split("."),r[i])}))}),s["--"]?o["--"]=z.slice():z.forEach(function(i){o._.push(i)}),o},x}var ce=ie();const le=re(ce),ue=1e4,fe=async e=>{await e.keyboard.press("Escape"),await new Promise(t=>setTimeout(t,500)),await e.keyboard.press("Tab"),await new Promise(t=>setTimeout(t,200)),await e.keyboard.down("Space"),await new Promise(t=>setTimeout(t,ue)),await e.keyboard.up("Space")},we=async()=>{try{const e=await $();if(!e)return!1;const t=(await e.pages())?.[0];if(!t)return!1;if(!(await t.title()).includes("denied"))return!0;for(let c=0;c<5;c++){try{await fe(t)}catch{}if(await t.reload({waitUntil:"load"}),!(await t.title()).includes("denied"))return!0;await new Promise(a=>setTimeout(a,3e3))}return!1}catch{return!1}};function de(e="zillow"){const t=q(),c=process.env.HOST??"127.0.0.1",a=process.env.PORT??8082;t.use(q.json());const s=le(process.argv.slice(2)).debug,n=t.listen(Number(a),async()=>{await N(e);const w=setInterval(async()=>{(await $())?.connected&&(clearInterval(w),s&&console.log("Browser listening at 127.0.0.1:9222"),e==="zillow"?await D():e==="redfin"&&(await Z(),await U()))},1e3);s&&console.log(`Server listening at ${c}:${a}`)}),p=async()=>(await U(),n.close(w=>{s&&console.log("server closed"),process.exit(w?1:0)}),{status:"shutdown"});return t.get("/server",(w,r)=>{try{r.send({running:!0})}catch(o){r.send(o)}}),t.post("/browser/launch",async(w,r)=>{try{const o=await N();r.send({browser:o})}catch(o){r.send(o)}}),t.post("/browser/status",async(w,r)=>{try{const o=await W();r.send({browser:o})}catch(o){r.send(o)}}),t.post("/browser/open",async(w,r)=>{try{const{url:o}=w?.body??{},T=await _(o);r.send({browser:T})}catch(o){r.send(o)}}),t.get("/cookie",async(w,r)=>{try{const o=await A();r.send({cookie:o})}catch(o){r.send(o)}}),t.post("/cookie/refresh",async(w,r)=>{try{const o=await J();r.send({cookie:o})}catch(o){r.send(o)}}),t.post("/cookie/save",async(w,r)=>{try{const o=await D();r.send({cookie:o})}catch(o){r.send(o)}}),t.post("/cookie/redfin/save",async(w,r)=>{try{const o=await Z();r.send({cookie:o})}catch(o){r.send(o)}}),t.post("/captcha/solve",async(w,r)=>{try{const o=await we();r.send({solved:o})}catch(o){r.send(o)}}),t.post("/browser/close",async(w,r)=>{try{const o=await S();r.send({browser:o})}catch(o){r.send(o)}}),t.post("/server/shutdown",(w,r)=>{try{const o=p();r.send({server:o})}catch(o){r.send(o)}}),process.on("SIGINT",p),process.on("SIGTERM",p),t}export{W as a,A as b,S as c,I as d,Z as e,D as f,$ as g,de as h,N as l,_ as o,J as r,U as s,se as w};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rent-scraper/browser-server",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -26,8 +26,8 @@
26
26
  "express": "^4.21.2",
27
27
  "picocolors": "^1.1.1",
28
28
  "puppeteer": "^24.11.2",
29
- "@rent-scraper/utils": "1.0.34",
30
- "@rent-scraper/api": "1.0.34"
29
+ "@rent-scraper/utils": "1.0.35",
30
+ "@rent-scraper/api": "1.0.35"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/express": "^5.0.3",
package/src/browser.ts CHANGED
@@ -70,7 +70,15 @@ export const getBrowser = async () => {
70
70
  export const closeBrowser = async () => {
71
71
  const browser = await getBrowser()
72
72
  const pages = await browser?.pages()
73
- if (pages) await Promise.all(pages.map(page => page.close()))
73
+ if (pages) {
74
+ if (process.platform === 'linux' && pages.length > 0) {
75
+ // on Linux, browsers exit when all windows close — navigate active page to blank and close the rest
76
+ await pages[0].goto('about:blank')
77
+ await Promise.all(pages.slice(1).map(page => page.close()))
78
+ } else {
79
+ await Promise.all(pages.map(page => page.close()))
80
+ }
81
+ }
74
82
  }
75
83
 
76
84
  export const launchBrowser = async (source = 'zillow' as ListingsSource) => {
@@ -1 +0,0 @@
1
- import x from"express";import E from"puppeteer";import{mkdtemp as X,access as Y}from"fs/promises";import{exec as k}from"child_process";import{tmpdir as ee}from"os";import te from"path";import{checkForConfigFile as oe,waitForConfigFile as ne,getValueFromConfigFile as ae,updateConfigFile as M}from"@rent-scraper/utils/config";import{parseError as L}from"@rent-scraper/utils";const j={darwin:["/Applications/Brave Browser.app/Contents/MacOS/Brave Browser","/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Chromium.app/Contents/MacOS/Chromium","/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"],linux:["/usr/bin/brave-browser","/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/usr/bin/chromium-browser","/usr/bin/chromium","/snap/bin/chromium"],win32:["C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe","C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"]},H=async()=>{const e=j[process.platform]??[];for(const t of e)try{return await Y(t),t}catch{}return null},V="http://127.0.0.1:9222/json/version",se=async(e=15e3)=>{const t=Date.now();for(;Date.now()-t<e;)try{await E.connect({browserURL:V});return}catch{await new Promise(c=>setTimeout(c,500))}throw new Error("timed out waiting for browser")},$=async()=>{try{return await E.connect({browserURL:V})}catch{return null}},S=async()=>{const e=await(await $())?.pages();e&&await Promise.all(e.map(t=>t.close()))},N=async(e="zillow")=>{if(await $())return{status:"already launched"};await oe(e)||await ne(e);const t=await X(te.join(ee(),"chrome-remote-")),c=await ae(e,"browser"),a=c?(j[process.platform]??[]).find(s=>s.toLowerCase().includes(c.toLowerCase()))??await H():await H();if(console.log(`launching browser: ${a??"bundled chromium"}`),a)k(`"${a}" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir="${t}"`,s=>{s&&console.error(`Error: ${s.message}`)});else{const s=["--remote-debugging-port=9222","--no-first-run","--no-default-browser-check",`--user-data-dir=${t}`,...process.platform==="linux"?["--no-sandbox","--disable-setuid-sandbox"]:[]];await E.launch({headless:!1,args:s,dumpio:!1})}return{status:"launched"}},W=async()=>{const e=await $();if(e){const t=(await e.pages())?.[0];return t?(await t.title()).includes("denied")?{status:"captcha"}:{status:"navigated"}:{status:"navigated"}}else return{status:"not connected"}},_=async e=>{const t=await $();if(t){const c=e,a=(await t.pages())?.[0]??await t.newPage();return(await a.title()).includes("denied")?{status:"captcha"}:(await a.goto(c,{waitUntil:"load"}),(await a.title()).includes("denied")?{status:"captcha"}:{status:"navigated"})}else return{status:"not connected"}},U=async()=>{const e=await $();if(e){try{await(await e.target().createCDPSession()).send("Browser.close")}catch{await e.disconnect()}return{status:"closed"}}else return{status:"not connected"}},G="http://127.0.0.1:9222/json/version",A=async(e=0)=>{const t=await E.connect({browserURL:G});e===0&&await _("https://www.zillow.com/homes/for_rent/");const c=await t.cookies(),[a]=c.filter(n=>n.name==="_pxvid"),[s]=c.filter(n=>n.name==="_px3");return a?(await S(),[a,s].filter(Boolean).map(n=>`${n.name}=${n.value}`).join("; ")):(console.log("refetching zillow cookie"),await new Promise(n=>setTimeout(n,2e3)),await A(e+1))},I=async(e=0)=>{const t=await E.connect({browserURL:G});e===0&&(await _("https://www.redfin.com"),await new Promise(n=>setTimeout(n,3e3)));const c=await t.pages(),a=c?.[0]?await c[0].title():"",s=(await t.cookies()).filter(n=>n.domain.includes("redfin.com"));return s.some(n=>n.name==="aws-waf-token")&&a.includes("Redfin")?(await S(),s.map(n=>`${n.name}=${n.value}`).join("; ")):(console.log("refetching redfin cookie"),await new Promise(n=>setTimeout(n,2e3)),await I(e+1))},Z=async()=>{try{const e=await I();e&&await M("redfin",{redfinCookie:e})}catch(e){const{status:t,message:c}=L(e);console.error(t,c)}},J=async()=>{try{const e=await(await E.connect({browserURL:G})).cookies(),[t]=e.filter(a=>a.name==="_pxvid"),[c]=e.filter(a=>a.name==="_px3");if(t){const a=[t,c].filter(Boolean).map(s=>`${s.name}=${s.value}`).join("; ");return await M("zillow",{zillowCookie:a}),a}}catch(e){const{status:t,message:c}=L(e);console.error(t,c)}},D=async()=>{try{const e=await A();e&&await M("zillow",{zillowCookie:e})}catch(e){const{status:t,message:c}=L(e);console.error(t,c)}};function re(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var K,Q;function ie(){if(Q)return K;Q=1;function e(a,s){var n=a;s.slice(0,-1).forEach(function(w){n=n[w]||{}});var p=s[s.length-1];return p in n}function t(a){return typeof a=="number"||/^0x[0-9a-f]+$/i.test(a)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(a)}function c(a,s){return s==="constructor"&&typeof a[s]=="function"||s==="__proto__"}return K=function(a,s){s||(s={});var n={bools:{},strings:{},unknownFn:null};typeof s.unknown=="function"&&(n.unknownFn=s.unknown),typeof s.boolean=="boolean"&&s.boolean?n.allBools=!0:[].concat(s.boolean).filter(Boolean).forEach(function(i){n.bools[i]=!0});var p={};function w(i){return p[i].some(function(d){return n.bools[d]})}Object.keys(s.alias||{}).forEach(function(i){p[i]=[].concat(s.alias[i]),p[i].forEach(function(d){p[d]=[i].concat(p[i].filter(function(C){return d!==C}))})}),[].concat(s.string).filter(Boolean).forEach(function(i){n.strings[i]=!0,p[i]&&[].concat(p[i]).forEach(function(d){n.strings[d]=!0})});var r=s.default||{},o={_:[]};function T(i,d){return n.allBools&&/^--[^=]+$/.test(d)||n.strings[i]||n.bools[i]||p[i]}function O(i,d,C){for(var u=i,F=0;F<d.length-1;F++){var y=d[F];if(c(u,y))return;u[y]===void 0&&(u[y]={}),(u[y]===Object.prototype||u[y]===Number.prototype||u[y]===String.prototype)&&(u[y]={}),u[y]===Array.prototype&&(u[y]=[]),u=u[y]}var B=d[d.length-1];c(u,B)||((u===Object.prototype||u===Number.prototype||u===String.prototype)&&(u={}),u===Array.prototype&&(u=[]),u[B]===void 0||n.bools[B]||typeof u[B]=="boolean"?u[B]=C:Array.isArray(u[B])?u[B].push(C):u[B]=[u[B],C])}function h(i,d,C){if(!(C&&n.unknownFn&&!T(i,C)&&n.unknownFn(C)===!1)){var u=!n.strings[i]&&t(d)?Number(d):d;O(o,i.split("."),u),(p[i]||[]).forEach(function(F){O(o,F.split("."),u)})}}Object.keys(n.bools).forEach(function(i){h(i,r[i]===void 0?!1:r[i])});var z=[];a.indexOf("--")!==-1&&(z=a.slice(a.indexOf("--")+1),a=a.slice(0,a.indexOf("--")));for(var m=0;m<a.length;m++){var l=a[m],f,v;if(/^--.+=/.test(l)){var q=l.match(/^--([^=]+)=([\s\S]*)$/);f=q[1];var R=q[2];n.bools[f]&&(R=R!=="false"),h(f,R,l)}else if(/^--no-.+/.test(l))f=l.match(/^--no-(.+)/)[1],h(f,!1,l);else if(/^--.+/.test(l))f=l.match(/^--(.+)/)[1],v=a[m+1],v!==void 0&&!/^(-|--)[^-]/.test(v)&&!n.bools[f]&&!n.allBools&&(!p[f]||!w(f))?(h(f,v,l),m+=1):/^(true|false)$/.test(v)?(h(f,v==="true",l),m+=1):h(f,n.strings[f]?"":!0,l);else if(/^-[^-]+/.test(l)){for(var g=l.slice(1,-1).split(""),P=!1,b=0;b<g.length;b++){if(v=l.slice(b+2),v==="-"){h(g[b],v,l);continue}if(/[A-Za-z]/.test(g[b])&&v[0]==="="){h(g[b],v.slice(1),l),P=!0;break}if(/[A-Za-z]/.test(g[b])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(v)){h(g[b],v,l),P=!0;break}if(g[b+1]&&g[b+1].match(/\W/)){h(g[b],l.slice(b+2),l),P=!0;break}else h(g[b],n.strings[g[b]]?"":!0,l)}f=l.slice(-1)[0],!P&&f!=="-"&&(a[m+1]&&!/^(-|--)[^-]/.test(a[m+1])&&!n.bools[f]&&(!p[f]||!w(f))?(h(f,a[m+1],l),m+=1):a[m+1]&&/^(true|false)$/.test(a[m+1])?(h(f,a[m+1]==="true",l),m+=1):h(f,n.strings[f]?"":!0,l))}else if((!n.unknownFn||n.unknownFn(l)!==!1)&&o._.push(n.strings._||!t(l)?l:Number(l)),s.stopEarly){o._.push.apply(o._,a.slice(m+1));break}}return Object.keys(r).forEach(function(i){e(o,i.split("."))||(O(o,i.split("."),r[i]),(p[i]||[]).forEach(function(d){O(o,d.split("."),r[i])}))}),s["--"]?o["--"]=z.slice():z.forEach(function(i){o._.push(i)}),o},K}var ce=ie();const le=re(ce),ue=1e4,fe=async e=>{await e.keyboard.press("Escape"),await new Promise(t=>setTimeout(t,500)),await e.keyboard.press("Tab"),await new Promise(t=>setTimeout(t,200)),await e.keyboard.down("Space"),await new Promise(t=>setTimeout(t,ue)),await e.keyboard.up("Space")},we=async()=>{try{const e=await $();if(!e)return!1;const t=(await e.pages())?.[0];if(!t)return!1;if(!(await t.title()).includes("denied"))return!0;for(let c=0;c<5;c++){try{await fe(t)}catch{}if(await t.reload({waitUntil:"load"}),!(await t.title()).includes("denied"))return!0;await new Promise(a=>setTimeout(a,3e3))}return!1}catch{return!1}};function de(e="zillow"){const t=x(),c=process.env.HOST??"127.0.0.1",a=process.env.PORT??8082;t.use(x.json());const s=le(process.argv.slice(2)).debug,n=t.listen(Number(a),async()=>{await N(e);const w=setInterval(async()=>{(await $())?.connected&&(clearInterval(w),s&&console.log("Browser listening at 127.0.0.1:9222"),e==="zillow"?await D():e==="redfin"&&(await Z(),await U()))},1e3);s&&console.log(`Server listening at ${c}:${a}`)}),p=async()=>(await U(),n.close(w=>{s&&console.log("server closed"),process.exit(w?1:0)}),{status:"shutdown"});return t.get("/server",(w,r)=>{try{r.send({running:!0})}catch(o){r.send(o)}}),t.post("/browser/launch",async(w,r)=>{try{const o=await N();r.send({browser:o})}catch(o){r.send(o)}}),t.post("/browser/status",async(w,r)=>{try{const o=await W();r.send({browser:o})}catch(o){r.send(o)}}),t.post("/browser/open",async(w,r)=>{try{const{url:o}=w?.body??{},T=await _(o);r.send({browser:T})}catch(o){r.send(o)}}),t.get("/cookie",async(w,r)=>{try{const o=await A();r.send({cookie:o})}catch(o){r.send(o)}}),t.post("/cookie/refresh",async(w,r)=>{try{const o=await J();r.send({cookie:o})}catch(o){r.send(o)}}),t.post("/cookie/save",async(w,r)=>{try{const o=await D();r.send({cookie:o})}catch(o){r.send(o)}}),t.post("/cookie/redfin/save",async(w,r)=>{try{const o=await Z();r.send({cookie:o})}catch(o){r.send(o)}}),t.post("/captcha/solve",async(w,r)=>{try{const o=await we();r.send({solved:o})}catch(o){r.send(o)}}),t.post("/browser/close",async(w,r)=>{try{const o=await S();r.send({browser:o})}catch(o){r.send(o)}}),t.post("/server/shutdown",(w,r)=>{try{const o=p();r.send({server:o})}catch(o){r.send(o)}}),process.on("SIGINT",p),process.on("SIGTERM",p),t}export{W as a,A as b,S as c,I as d,Z as e,D as f,$ as g,de as h,N as l,_ as o,J as r,U as s,se as w};