@rent-scraper/browser-server 1.0.35 → 1.0.37
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.
|
|
2
|
+
import{h as r}from"../shared/browser-server.Cvug5U8h.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.
|
|
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.Cvug5U8h.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 U}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 t=j[process.platform]??[];for(const e of t)try{return await Y(e),e}catch{}return null},V="http://127.0.0.1:9222/json/version",se=async(t=15e3)=>{const e=Date.now();for(;Date.now()-e<t;)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 t=await $(),e=await t?.pages();e&&(process.platform==="linux"&&t?(await t.newPage(),await Promise.all(e.map(c=>c.close()))):await Promise.all(e.map(c=>c.close())))},L=async(t="zillow")=>{if(await $())return{status:"already launched"};await oe(t)||await ne(t);const e=await X(te.join(ee(),"chrome-remote-")),c=await ae(t,"browser"),n=c?(j[process.platform]??[]).find(s=>s.toLowerCase().includes(c.toLowerCase()))??await H():await H();if(console.log(`launching browser: ${n??"bundled chromium"}`),n)k(`"${n}" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir="${e}"`,s=>{s&&console.error(`Error: ${s.message}`)});else{const s=["--remote-debugging-port=9222","--no-first-run","--no-default-browser-check",`--user-data-dir=${e}`,...process.platform==="linux"?["--no-sandbox","--disable-setuid-sandbox"]:[]];await E.launch({headless:!1,args:s,dumpio:!1})}return{status:"launched"}},W=async()=>{const t=await $();if(t){const e=(await t.pages())?.[0];return e?(await e.title()).includes("denied")?{status:"captcha"}:{status:"navigated"}:{status:"navigated"}}else return{status:"not connected"}},_=async t=>{const e=await $();if(e){const c=t,n=(await e.pages())?.[0]??await e.newPage();if((await n.title()).includes("denied"))return{status:"captcha"};if(process.platform==="linux")try{await n.goto(c,{waitUntil:"domcontentloaded",timeout:6e4})}catch{}else await n.goto(c,{waitUntil:"load"});return(await n.title().catch(()=>"")).includes("denied")?{status:"captcha"}:{status:"navigated"}}else return{status:"not connected"}},N=async()=>{const t=await $();if(t){try{await(await t.target().createCDPSession()).send("Browser.close")}catch{await t.disconnect()}return{status:"closed"}}else return{status:"not connected"}},G="http://127.0.0.1:9222/json/version",A=async(t=0)=>{const e=await E.connect({browserURL:G});t===0&&await _("https://www.zillow.com/homes/for_rent/");const c=await e.cookies(),[n]=c.filter(a=>a.name==="_pxvid"),[s]=c.filter(a=>a.name==="_px3");return n?(await S(),[n,s].filter(Boolean).map(a=>`${a.name}=${a.value}`).join("; ")):(console.log("refetching zillow cookie"),await new Promise(a=>setTimeout(a,2e3)),await A(t+1))},I=async(t=0)=>{const e=await E.connect({browserURL:G});t===0&&(await _("https://www.redfin.com"),await new Promise(a=>setTimeout(a,3e3)));const c=await e.pages(),n=c?.[0]?await c[0].title():"",s=(await e.cookies()).filter(a=>a.domain.includes("redfin.com"));return s.some(a=>a.name==="aws-waf-token")&&n.includes("Redfin")?(await S(),s.map(a=>`${a.name}=${a.value}`).join("; ")):(console.log("refetching redfin cookie"),await new Promise(a=>setTimeout(a,2e3)),await I(t+1))},Z=async()=>{try{const t=await I();t&&await M("redfin",{redfinCookie:t})}catch(t){const{status:e,message:c}=U(t);console.error(e,c)}},J=async()=>{try{const t=await(await E.connect({browserURL:G})).cookies(),[e]=t.filter(n=>n.name==="_pxvid"),[c]=t.filter(n=>n.name==="_px3");if(e){const n=[e,c].filter(Boolean).map(s=>`${s.name}=${s.value}`).join("; ");return await M("zillow",{zillowCookie:n}),n}}catch(t){const{status:e,message:c}=U(t);console.error(e,c)}},D=async()=>{try{const t=await A();t&&await M("zillow",{zillowCookie:t})}catch(t){const{status:e,message:c}=U(t);console.error(e,c)}};function re(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var x,Q;function ie(){if(Q)return x;Q=1;function t(n,s){var a=n;s.slice(0,-1).forEach(function(w){a=a[w]||{}});var p=s[s.length-1];return p in a}function e(n){return typeof n=="number"||/^0x[0-9a-f]+$/i.test(n)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(n)}function c(n,s){return s==="constructor"&&typeof n[s]=="function"||s==="__proto__"}return x=function(n,s){s||(s={});var a={bools:{},strings:{},unknownFn:null};typeof s.unknown=="function"&&(a.unknownFn=s.unknown),typeof s.boolean=="boolean"&&s.boolean?a.allBools=!0:[].concat(s.boolean).filter(Boolean).forEach(function(i){a.bools[i]=!0});var p={};function w(i){return p[i].some(function(d){return a.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){a.strings[i]=!0,p[i]&&[].concat(p[i]).forEach(function(d){a.strings[d]=!0})});var r=s.default||{},o={_:[]};function T(i,d){return a.allBools&&/^--[^=]+$/.test(d)||a.strings[i]||a.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||a.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&&a.unknownFn&&!T(i,C)&&a.unknownFn(C)===!1)){var u=!a.strings[i]&&e(d)?Number(d):d;P(o,i.split("."),u),(p[i]||[]).forEach(function(F){P(o,F.split("."),u)})}}Object.keys(a.bools).forEach(function(i){h(i,r[i]===void 0?!1:r[i])});var z=[];n.indexOf("--")!==-1&&(z=n.slice(n.indexOf("--")+1),n=n.slice(0,n.indexOf("--")));for(var m=0;m<n.length;m++){var l=n[m],f,v;if(/^--.+=/.test(l)){var K=l.match(/^--([^=]+)=([\s\S]*)$/);f=K[1];var R=K[2];a.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=n[m+1],v!==void 0&&!/^(-|--)[^-]/.test(v)&&!a.bools[f]&&!a.allBools&&(!p[f]||!w(f))?(h(f,v,l),m+=1):/^(true|false)$/.test(v)?(h(f,v==="true",l),m+=1):h(f,a.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],a.strings[g[b]]?"":!0,l)}f=l.slice(-1)[0],!O&&f!=="-"&&(n[m+1]&&!/^(-|--)[^-]/.test(n[m+1])&&!a.bools[f]&&(!p[f]||!w(f))?(h(f,n[m+1],l),m+=1):n[m+1]&&/^(true|false)$/.test(n[m+1])?(h(f,n[m+1]==="true",l),m+=1):h(f,a.strings[f]?"":!0,l))}else if((!a.unknownFn||a.unknownFn(l)!==!1)&&o._.push(a.strings._||!e(l)?l:Number(l)),s.stopEarly){o._.push.apply(o._,n.slice(m+1));break}}return Object.keys(r).forEach(function(i){t(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 t=>{await t.keyboard.press("Escape"),await new Promise(e=>setTimeout(e,500)),await t.keyboard.press("Tab"),await new Promise(e=>setTimeout(e,200)),await t.keyboard.down("Space"),await new Promise(e=>setTimeout(e,ue)),await t.keyboard.up("Space")},we=async()=>{try{const t=await $();if(!t)return!1;const e=(await t.pages())?.[0];if(!e)return!1;if(!(await e.title()).includes("denied"))return!0;for(let c=0;c<5;c++){try{await fe(e)}catch{}if(await e.reload({waitUntil:"load"}),!(await e.title()).includes("denied"))return!0;await new Promise(n=>setTimeout(n,3e3))}return!1}catch{return!1}};function de(t="zillow"){const e=q(),c=process.env.HOST??"127.0.0.1",n=process.env.PORT??8082;e.use(q.json());const s=le(process.argv.slice(2)).debug,a=e.listen(Number(n),async()=>{await L(t);const w=setInterval(async()=>{(await $())?.connected&&(clearInterval(w),s&&console.log("Browser listening at 127.0.0.1:9222"),t==="zillow"?await D():t==="redfin"&&(await Z(),await N()))},1e3);s&&console.log(`Server listening at ${c}:${n}`)}),p=async()=>(await N(),a.close(w=>{s&&console.log("server closed"),process.exit(w?1:0)}),{status:"shutdown"});return e.get("/server",(w,r)=>{try{r.send({running:!0})}catch(o){r.send(o)}}),e.post("/browser/launch",async(w,r)=>{try{const o=await L();r.send({browser:o})}catch(o){r.send(o)}}),e.post("/browser/status",async(w,r)=>{try{const o=await W();r.send({browser:o})}catch(o){r.send(o)}}),e.post("/browser/open",async(w,r)=>{try{const{url:o}=w?.body??{},T=await _(o);r.send({browser:T})}catch(o){r.send(o)}}),e.get("/cookie",async(w,r)=>{try{const o=await A();r.send({cookie:o})}catch(o){r.send(o)}}),e.post("/cookie/refresh",async(w,r)=>{try{const o=await J();r.send({cookie:o})}catch(o){r.send(o)}}),e.post("/cookie/save",async(w,r)=>{try{const o=await D();r.send({cookie:o})}catch(o){r.send(o)}}),e.post("/cookie/redfin/save",async(w,r)=>{try{const o=await Z();r.send({cookie:o})}catch(o){r.send(o)}}),e.post("/captcha/solve",async(w,r)=>{try{const o=await we();r.send({solved:o})}catch(o){r.send(o)}}),e.post("/browser/close",async(w,r)=>{try{const o=await S();r.send({browser:o})}catch(o){r.send(o)}}),e.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),e}export{W as a,A as b,S as c,I as d,Z as e,D as f,$ as g,de as h,L as l,_ as o,J as r,N 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.
|
|
3
|
+
"version": "1.0.37",
|
|
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/
|
|
30
|
-
"@rent-scraper/
|
|
29
|
+
"@rent-scraper/api": "1.0.37",
|
|
30
|
+
"@rent-scraper/utils": "1.0.37"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/express": "^5.0.3",
|
package/src/browser.ts
CHANGED
|
@@ -71,10 +71,11 @@ export const closeBrowser = async () => {
|
|
|
71
71
|
const browser = await getBrowser()
|
|
72
72
|
const pages = await browser?.pages()
|
|
73
73
|
if (pages) {
|
|
74
|
-
if (process.platform === 'linux' &&
|
|
75
|
-
// on Linux, browsers exit when all windows close —
|
|
76
|
-
|
|
77
|
-
await
|
|
74
|
+
if (process.platform === 'linux' && browser) {
|
|
75
|
+
// on Linux, browsers exit when all windows close — open a fresh tab first to keep the process alive,
|
|
76
|
+
// then close all old tabs
|
|
77
|
+
await browser.newPage()
|
|
78
|
+
await Promise.all(pages.map(page => page.close()))
|
|
78
79
|
} else {
|
|
79
80
|
await Promise.all(pages.map(page => page.close()))
|
|
80
81
|
}
|
|
@@ -139,11 +140,17 @@ export const openBrowser = async (url: string) => {
|
|
|
139
140
|
if (pageTitle.includes('denied')) {
|
|
140
141
|
return { status: 'captcha' }
|
|
141
142
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
if (process.platform === 'linux') {
|
|
144
|
+
try {
|
|
145
|
+
await page.goto(pageUrl, { waitUntil: 'domcontentloaded', timeout: 60000 })
|
|
146
|
+
} catch {
|
|
147
|
+
// navigation error — page may still have content, fall through to title check
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
await page.goto(pageUrl, { waitUntil: 'load' })
|
|
151
|
+
}
|
|
145
152
|
// check title after navigation — zillow may have shown a captcha as a result of the request
|
|
146
|
-
const titleAfterNav = await page.title()
|
|
153
|
+
const titleAfterNav = await page.title().catch(() => '')
|
|
147
154
|
if (titleAfterNav.includes('denied')) {
|
|
148
155
|
return { status: 'captcha' }
|
|
149
156
|
}
|
|
@@ -1 +0,0 @@
|
|
|
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};
|