@rent-scraper/browser-server 1.0.23 → 1.0.25
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{r}from"../shared/browser-server.
|
|
2
|
+
import{r}from"../shared/browser-server.C-q4WCe-.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.d.mts
CHANGED
|
@@ -22,10 +22,14 @@ declare const shutdownBrowser: () => Promise<{
|
|
|
22
22
|
|
|
23
23
|
declare function runConfirmBrowserLaunch(): Promise<undefined>;
|
|
24
24
|
|
|
25
|
-
declare const getZillowCookie: (attempt?: number
|
|
25
|
+
declare const getZillowCookie: (attempt?: number, options?: {
|
|
26
|
+
onCaptcha?: () => Promise<void>;
|
|
27
|
+
}) => Promise<string | undefined>;
|
|
26
28
|
declare const getRedfinCookie: (attempt?: number) => Promise<string | undefined>;
|
|
27
29
|
declare const saveRedfinCookie: () => Promise<void>;
|
|
28
|
-
declare const saveZillowCookie: (
|
|
30
|
+
declare const saveZillowCookie: (options?: {
|
|
31
|
+
onCaptcha?: () => Promise<void>;
|
|
32
|
+
}) => Promise<void>;
|
|
29
33
|
|
|
30
34
|
// This extracts the core definitions from express to prevent a circular dependency between express and serve-static
|
|
31
35
|
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{c as closeBrowser,g as getBrowser,b as getRedfinCookie,a as getZillowCookie,l as launchBrowser,o as openBrowser,r as runBrowserServer,d as saveRedfinCookie,e as saveZillowCookie,s as shutdownBrowser,w as waitForBrowser}from"./shared/browser-server.
|
|
1
|
+
export{c as closeBrowser,g as getBrowser,b as getRedfinCookie,a as getZillowCookie,l as launchBrowser,o as openBrowser,r as runBrowserServer,d as saveRedfinCookie,e as saveZillowCookie,s as shutdownBrowser,w as waitForBrowser}from"./shared/browser-server.C-q4WCe-.mjs";import{confirm as r,isCancel as a,cancel as i,outro as s}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 i("Create config canceled. Please try again."),process.exit(1);await o(1e3),s("Browser Launching..."),await o(1e3)}export{t as runConfirmBrowserLaunch};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import Z from"express";import O from"puppeteer";import{mkdtemp as J,access as Q}from"fs/promises";import{exec as V}from"child_process";import{tmpdir as X}from"os";import Y from"path";import{checkForConfigFile as x,waitForConfigFile as k,updateConfigFile as K}from"@rent-scraper/utils/config";import{parseError as q}from"@rent-scraper/utils";const oo={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"]},eo=async()=>{const s=oo[process.platform]??[];for(const e of s)try{return await Q(e),e}catch{}return null},H="http://127.0.0.1:9222/json/version",to=async(s=15e3)=>{const e=Date.now();for(;Date.now()-e<s;)try{await O.connect({browserURL:H});return}catch{await new Promise(u=>setTimeout(u,500))}throw new Error("timed out waiting for browser")},E=async()=>{try{return await O.connect({browserURL:H})}catch{return null}},P=async()=>{const s=await(await E())?.pages();s&&await Promise.all(s.map(e=>e.close()))},T=async(s="zillow")=>{if(await E())return{status:"already launched"};await x(s)||await k(s);const e=await J(Y.join(X(),"chrome-remote-")),u=await eo();if(console.log(`launching browser: ${u??"bundled chromium"}`),u)V(`"${u}" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir="${e}"`,t=>{t&&console.error(`Error: ${t.message}`)});else{const t=["--remote-debugging-port=9222","--no-first-run","--no-default-browser-check",`--user-data-dir=${e}`,...process.platform==="linux"?["--no-sandbox","--disable-setuid-sandbox"]:[]];await O.launch({headless:!1,args:t,dumpio:!1})}return{status:"launched"}},S=async s=>{const e=await E();if(e){const u=s,t=(await e.pages())?.[0]??await e.newPage();return(await t.title()).includes("denied")||await t.goto(u,{waitUntil:"load"}),{status:"opened"}}else return{status:"not connected"}},N=async()=>{const s=await E();return s?(await s.close(),{status:"closed"}):{status:"not connected"}},W="http://127.0.0.1:9222/json/version",A=async(s=0,e)=>{const u=await O.connect({browserURL:W});s===0&&await S("https://www.zillow.com/homes/for_rent/");const t=await u.pages();if((t?.[0]?await t[0].title():"").includes("Access to this page has been denied"))return e?.onCaptcha?await e.onCaptcha():await new Promise(o=>setTimeout(o,2e3)),await A(s+1,e);const a=(await u.cookies()).filter(o=>o.domain?.includes("zillow.com"));return a.some(o=>o.name==="_pxvid")?(await P(),a.map(o=>`${o.name}=${o.value}`).join("; ")):(console.log("refetching zillow cookie"),await new Promise(o=>setTimeout(o,2e3)),await A(s+1))},G=async(s=0)=>{const e=await O.connect({browserURL:W});s===0&&(await S("https://www.redfin.com"),await new Promise(o=>setTimeout(o,3e3)));const u=await e.pages(),t=u?.[0]?await u[0].title():"",a=(await e.cookies()).filter(o=>o.domain.includes("redfin.com"));return a.some(o=>o.name==="aws-waf-token")&&t.includes("Redfin")?(await P(),a.map(o=>`${o.name}=${o.value}`).join("; ")):(console.log("refetching redfin cookie"),await new Promise(o=>setTimeout(o,2e3)),await G(s+1))},I=async()=>{try{const s=await G();s&&await K("redfin",{redfinCookie:s})}catch(s){const{status:e,message:u}=q(s);console.error(e,u)}},U=async s=>{try{const e=await A(0,s);e&&await K("zillow",{zillowCookie:e})}catch(e){const{status:u,message:t}=q(e);console.error(u,t)}};function no(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var D,j;function so(){if(j)return D;j=1;function s(t,a){var o=t;a.slice(0,-1).forEach(function(p){o=o[p]||{}});var d=a[a.length-1];return d in o}function e(t){return typeof t=="number"||/^0x[0-9a-f]+$/i.test(t)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(t)}function u(t,a){return a==="constructor"&&typeof t[a]=="function"||a==="__proto__"}return D=function(t,a){a||(a={});var o={bools:{},strings:{},unknownFn:null};typeof a.unknown=="function"&&(o.unknownFn=a.unknown),typeof a.boolean=="boolean"&&a.boolean?o.allBools=!0:[].concat(a.boolean).filter(Boolean).forEach(function(r){o.bools[r]=!0});var d={};function p(r){return d[r].some(function(w){return o.bools[w]})}Object.keys(a.alias||{}).forEach(function(r){d[r]=[].concat(a.alias[r]),d[r].forEach(function(w){d[w]=[r].concat(d[r].filter(function(B){return w!==B}))})}),[].concat(a.string).filter(Boolean).forEach(function(r){o.strings[r]=!0,d[r]&&[].concat(d[r]).forEach(function(w){o.strings[w]=!0})});var i=a.default||{},n={_:[]};function z(r,w){return o.allBools&&/^--[^=]+$/.test(w)||o.strings[r]||o.bools[r]||d[r]}function y(r,w,B){for(var l=r,F=0;F<w.length-1;F++){var C=w[F];if(u(l,C))return;l[C]===void 0&&(l[C]={}),(l[C]===Object.prototype||l[C]===Number.prototype||l[C]===String.prototype)&&(l[C]={}),l[C]===Array.prototype&&(l[C]=[]),l=l[C]}var $=w[w.length-1];u(l,$)||((l===Object.prototype||l===Number.prototype||l===String.prototype)&&(l={}),l===Array.prototype&&(l=[]),l[$]===void 0||o.bools[$]||typeof l[$]=="boolean"?l[$]=B:Array.isArray(l[$])?l[$].push(B):l[$]=[l[$],B])}function h(r,w,B){if(!(B&&o.unknownFn&&!z(r,B)&&o.unknownFn(B)===!1)){var l=!o.strings[r]&&e(w)?Number(w):w;y(n,r.split("."),l),(d[r]||[]).forEach(function(F){y(n,F.split("."),l)})}}Object.keys(o.bools).forEach(function(r){h(r,i[r]===void 0?!1:i[r])});var M=[];t.indexOf("--")!==-1&&(M=t.slice(t.indexOf("--")+1),t=t.slice(0,t.indexOf("--")));for(var m=0;m<t.length;m++){var c=t[m],f,v;if(/^--.+=/.test(c)){var L=c.match(/^--([^=]+)=([\s\S]*)$/);f=L[1];var R=L[2];o.bools[f]&&(R=R!=="false"),h(f,R,c)}else if(/^--no-.+/.test(c))f=c.match(/^--no-(.+)/)[1],h(f,!1,c);else if(/^--.+/.test(c))f=c.match(/^--(.+)/)[1],v=t[m+1],v!==void 0&&!/^(-|--)[^-]/.test(v)&&!o.bools[f]&&!o.allBools&&(!d[f]||!p(f))?(h(f,v,c),m+=1):/^(true|false)$/.test(v)?(h(f,v==="true",c),m+=1):h(f,o.strings[f]?"":!0,c);else if(/^-[^-]+/.test(c)){for(var g=c.slice(1,-1).split(""),_=!1,b=0;b<g.length;b++){if(v=c.slice(b+2),v==="-"){h(g[b],v,c);continue}if(/[A-Za-z]/.test(g[b])&&v[0]==="="){h(g[b],v.slice(1),c),_=!0;break}if(/[A-Za-z]/.test(g[b])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(v)){h(g[b],v,c),_=!0;break}if(g[b+1]&&g[b+1].match(/\W/)){h(g[b],c.slice(b+2),c),_=!0;break}else h(g[b],o.strings[g[b]]?"":!0,c)}f=c.slice(-1)[0],!_&&f!=="-"&&(t[m+1]&&!/^(-|--)[^-]/.test(t[m+1])&&!o.bools[f]&&(!d[f]||!p(f))?(h(f,t[m+1],c),m+=1):t[m+1]&&/^(true|false)$/.test(t[m+1])?(h(f,t[m+1]==="true",c),m+=1):h(f,o.strings[f]?"":!0,c))}else if((!o.unknownFn||o.unknownFn(c)!==!1)&&n._.push(o.strings._||!e(c)?c:Number(c)),a.stopEarly){n._.push.apply(n._,t.slice(m+1));break}}return Object.keys(i).forEach(function(r){s(n,r.split("."))||(y(n,r.split("."),i[r]),(d[r]||[]).forEach(function(w){y(n,w.split("."),i[r])}))}),a["--"]?n["--"]=M.slice():M.forEach(function(r){n._.push(r)}),n},D}var ro=so();const ao=no(ro);function io(s="zillow"){const e=Z(),u=process.env.HOST??"127.0.0.1",t=process.env.PORT??8082;e.use(Z.json());const a=ao(process.argv.slice(2)).debug,o=e.listen(Number(t),async()=>{await T(s);const p=setInterval(async()=>{(await E())?.connected&&(clearInterval(p),a&&console.log("Browser listening at 127.0.0.1:9222"),s==="zillow"?await U():s==="redfin"&&(await I(),await N()))},1e3);a&&console.log(`Server listening at ${u}:${t}`)}),d=()=>(o.close(async p=>{const i=await N();a&&(console.log(i),console.log("server closed")),process.exit(p?1:0)}),{status:"shutdown"});return e.get("/server",(p,i)=>{try{i.send({running:!0})}catch(n){i.send(n)}}),e.post("/browser/launch",async(p,i)=>{try{const n=await T();i.send({browser:n})}catch(n){i.send(n)}}),e.post("/browser/open",async(p,i)=>{try{const{url:n}=p?.body??{},z=await S(n);i.send({browser:z})}catch(n){i.send(n)}}),e.get("/cookie",async(p,i)=>{try{const n=await A();i.send({cookie:n})}catch(n){i.send(n)}}),e.post("/cookie/save",async(p,i)=>{try{const n=await U();i.send({cookie:n})}catch(n){i.send(n)}}),e.post("/cookie/redfin/save",async(p,i)=>{try{const n=await I();i.send({cookie:n})}catch(n){i.send(n)}}),e.post("/browser/close",async(p,i)=>{try{const n=await P();i.send({browser:n})}catch(n){i.send(n)}}),e.post("/server/shutdown",(p,i)=>{try{const n=d();i.send({server:n})}catch(n){i.send(n)}}),process.on("SIGINT",d),process.on("SIGTERM",d),e}export{A as a,G as b,P as c,I as d,U as e,E as g,T as l,S as o,io as r,N as s,to 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.25",
|
|
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.
|
|
30
|
-
"@rent-scraper/api": "1.0.
|
|
29
|
+
"@rent-scraper/utils": "1.0.25",
|
|
30
|
+
"@rent-scraper/api": "1.0.25"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/express": "^5.0.3",
|
package/src/cookie.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { parseError } from '@rent-scraper/utils'
|
|
|
5
5
|
|
|
6
6
|
const wsChromeEndpointurl = 'http://127.0.0.1:9222/json/version'
|
|
7
7
|
|
|
8
|
-
export const getZillowCookie = async (attempt = 0): Promise<string | undefined> => {
|
|
8
|
+
export const getZillowCookie = async (attempt = 0, options?: { onCaptcha?: () => Promise<void> }): Promise<string | undefined> => {
|
|
9
9
|
const browser = await puppeteer.connect({
|
|
10
10
|
browserURL: wsChromeEndpointurl,
|
|
11
11
|
})
|
|
@@ -15,8 +15,12 @@ export const getZillowCookie = async (attempt = 0): Promise<string | undefined>
|
|
|
15
15
|
const pages = await browser.pages()
|
|
16
16
|
const title = pages?.[0] ? await pages[0].title() : ''
|
|
17
17
|
if (title.includes('Access to this page has been denied')) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
if (options?.onCaptcha) {
|
|
19
|
+
await options.onCaptcha()
|
|
20
|
+
} else {
|
|
21
|
+
await new Promise(resolve => setTimeout(resolve, 2000))
|
|
22
|
+
}
|
|
23
|
+
return await getZillowCookie(attempt + 1, options)
|
|
20
24
|
}
|
|
21
25
|
const allCookies = await browser.cookies()
|
|
22
26
|
const zillowCookies = allCookies.filter(c => c.domain?.includes('zillow.com'))
|
|
@@ -64,9 +68,9 @@ export const saveRedfinCookie = async () => {
|
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
export const saveZillowCookie = async () => {
|
|
71
|
+
export const saveZillowCookie = async (options?: { onCaptcha?: () => Promise<void> }) => {
|
|
68
72
|
try {
|
|
69
|
-
const zillowCookie = await getZillowCookie()
|
|
73
|
+
const zillowCookie = await getZillowCookie(0, options)
|
|
70
74
|
if (zillowCookie) {
|
|
71
75
|
await updateConfigFile('zillow', { zillowCookie })
|
|
72
76
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import Z from"express";import O from"puppeteer";import{mkdtemp as J,access as Q}from"fs/promises";import{exec as V}from"child_process";import{tmpdir as X}from"os";import Y from"path";import{checkForConfigFile as x,waitForConfigFile as k,updateConfigFile as K}from"@rent-scraper/utils/config";import{parseError as q}from"@rent-scraper/utils";const ee={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"]},oe=async()=>{const e=ee[process.platform]??[];for(const r of e)try{return await Q(r),r}catch{}return null},H="http://127.0.0.1:9222/json/version",te=async(e=15e3)=>{const r=Date.now();for(;Date.now()-r<e;)try{await O.connect({browserURL:H});return}catch{await new Promise(u=>setTimeout(u,500))}throw new Error("timed out waiting for browser")},$=async()=>{try{return await O.connect({browserURL:H})}catch{return null}},P=async()=>{const e=await(await $())?.pages();e&&await Promise.all(e.map(r=>r.close()))},T=async(e="zillow")=>{if(await $())return{status:"already launched"};await x(e)||await k(e);const r=await J(Y.join(X(),"chrome-remote-")),u=await oe();if(console.log(`launching browser: ${u??"bundled chromium"}`),u)V(`"${u}" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir="${r}"`,n=>{n&&console.error(`Error: ${n.message}`)});else{const n=["--remote-debugging-port=9222","--no-first-run","--no-default-browser-check",`--user-data-dir=${r}`,...process.platform==="linux"?["--no-sandbox","--disable-setuid-sandbox"]:[]];await O.launch({headless:!1,args:n,dumpio:!1})}return{status:"launched"}},S=async e=>{const r=await $();if(r){const u=e,n=(await r.pages())?.[0]??await r.newPage();return(await n.title()).includes("denied")||await n.goto(u,{waitUntil:"load"}),{status:"opened"}}else return{status:"not connected"}},N=async()=>{const e=await $();return e?(await e.close(),{status:"closed"}):{status:"not connected"}},W="http://127.0.0.1:9222/json/version",A=async(e=0)=>{const r=await O.connect({browserURL:W});e===0&&await S("https://www.zillow.com/homes/for_rent/");const u=await r.pages();if((u?.[0]?await u[0].title():"").includes("Access to this page has been denied"))return await new Promise(s=>setTimeout(s,2e3)),await A(e+1);const n=(await r.cookies()).filter(s=>s.domain?.includes("zillow.com"));return n.some(s=>s.name==="_pxvid")?(await P(),n.map(s=>`${s.name}=${s.value}`).join("; ")):(console.log("refetching zillow cookie"),await new Promise(s=>setTimeout(s,2e3)),await A(e+1))},G=async(e=0)=>{const r=await O.connect({browserURL:W});e===0&&(await S("https://www.redfin.com"),await new Promise(o=>setTimeout(o,3e3)));const u=await r.pages(),n=u?.[0]?await u[0].title():"",s=(await r.cookies()).filter(o=>o.domain.includes("redfin.com"));return s.some(o=>o.name==="aws-waf-token")&&n.includes("Redfin")?(await P(),s.map(o=>`${o.name}=${o.value}`).join("; ")):(console.log("refetching redfin cookie"),await new Promise(o=>setTimeout(o,2e3)),await G(e+1))},I=async()=>{try{const e=await G();e&&await K("redfin",{redfinCookie:e})}catch(e){const{status:r,message:u}=q(e);console.error(r,u)}},U=async()=>{try{const e=await A();e&&await K("zillow",{zillowCookie:e})}catch(e){const{status:r,message:u}=q(e);console.error(r,u)}};function ne(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var D,j;function se(){if(j)return D;j=1;function e(n,s){var o=n;s.slice(0,-1).forEach(function(p){o=o[p]||{}});var d=s[s.length-1];return d in o}function r(n){return typeof n=="number"||/^0x[0-9a-f]+$/i.test(n)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(n)}function u(n,s){return s==="constructor"&&typeof n[s]=="function"||s==="__proto__"}return D=function(n,s){s||(s={});var o={bools:{},strings:{},unknownFn:null};typeof s.unknown=="function"&&(o.unknownFn=s.unknown),typeof s.boolean=="boolean"&&s.boolean?o.allBools=!0:[].concat(s.boolean).filter(Boolean).forEach(function(i){o.bools[i]=!0});var d={};function p(i){return d[i].some(function(w){return o.bools[w]})}Object.keys(s.alias||{}).forEach(function(i){d[i]=[].concat(s.alias[i]),d[i].forEach(function(w){d[w]=[i].concat(d[i].filter(function(B){return w!==B}))})}),[].concat(s.string).filter(Boolean).forEach(function(i){o.strings[i]=!0,d[i]&&[].concat(d[i]).forEach(function(w){o.strings[w]=!0})});var a=s.default||{},t={_:[]};function z(i,w){return o.allBools&&/^--[^=]+$/.test(w)||o.strings[i]||o.bools[i]||d[i]}function y(i,w,B){for(var l=i,F=0;F<w.length-1;F++){var C=w[F];if(u(l,C))return;l[C]===void 0&&(l[C]={}),(l[C]===Object.prototype||l[C]===Number.prototype||l[C]===String.prototype)&&(l[C]={}),l[C]===Array.prototype&&(l[C]=[]),l=l[C]}var E=w[w.length-1];u(l,E)||((l===Object.prototype||l===Number.prototype||l===String.prototype)&&(l={}),l===Array.prototype&&(l=[]),l[E]===void 0||o.bools[E]||typeof l[E]=="boolean"?l[E]=B:Array.isArray(l[E])?l[E].push(B):l[E]=[l[E],B])}function h(i,w,B){if(!(B&&o.unknownFn&&!z(i,B)&&o.unknownFn(B)===!1)){var l=!o.strings[i]&&r(w)?Number(w):w;y(t,i.split("."),l),(d[i]||[]).forEach(function(F){y(t,F.split("."),l)})}}Object.keys(o.bools).forEach(function(i){h(i,a[i]===void 0?!1:a[i])});var M=[];n.indexOf("--")!==-1&&(M=n.slice(n.indexOf("--")+1),n=n.slice(0,n.indexOf("--")));for(var m=0;m<n.length;m++){var c=n[m],f,v;if(/^--.+=/.test(c)){var L=c.match(/^--([^=]+)=([\s\S]*)$/);f=L[1];var R=L[2];o.bools[f]&&(R=R!=="false"),h(f,R,c)}else if(/^--no-.+/.test(c))f=c.match(/^--no-(.+)/)[1],h(f,!1,c);else if(/^--.+/.test(c))f=c.match(/^--(.+)/)[1],v=n[m+1],v!==void 0&&!/^(-|--)[^-]/.test(v)&&!o.bools[f]&&!o.allBools&&(!d[f]||!p(f))?(h(f,v,c),m+=1):/^(true|false)$/.test(v)?(h(f,v==="true",c),m+=1):h(f,o.strings[f]?"":!0,c);else if(/^-[^-]+/.test(c)){for(var g=c.slice(1,-1).split(""),_=!1,b=0;b<g.length;b++){if(v=c.slice(b+2),v==="-"){h(g[b],v,c);continue}if(/[A-Za-z]/.test(g[b])&&v[0]==="="){h(g[b],v.slice(1),c),_=!0;break}if(/[A-Za-z]/.test(g[b])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(v)){h(g[b],v,c),_=!0;break}if(g[b+1]&&g[b+1].match(/\W/)){h(g[b],c.slice(b+2),c),_=!0;break}else h(g[b],o.strings[g[b]]?"":!0,c)}f=c.slice(-1)[0],!_&&f!=="-"&&(n[m+1]&&!/^(-|--)[^-]/.test(n[m+1])&&!o.bools[f]&&(!d[f]||!p(f))?(h(f,n[m+1],c),m+=1):n[m+1]&&/^(true|false)$/.test(n[m+1])?(h(f,n[m+1]==="true",c),m+=1):h(f,o.strings[f]?"":!0,c))}else if((!o.unknownFn||o.unknownFn(c)!==!1)&&t._.push(o.strings._||!r(c)?c:Number(c)),s.stopEarly){t._.push.apply(t._,n.slice(m+1));break}}return Object.keys(a).forEach(function(i){e(t,i.split("."))||(y(t,i.split("."),a[i]),(d[i]||[]).forEach(function(w){y(t,w.split("."),a[i])}))}),s["--"]?t["--"]=M.slice():M.forEach(function(i){t._.push(i)}),t},D}var re=se();const ie=ne(re);function ae(e="zillow"){const r=Z(),u=process.env.HOST??"127.0.0.1",n=process.env.PORT??8082;r.use(Z.json());const s=ie(process.argv.slice(2)).debug,o=r.listen(Number(n),async()=>{await T(e);const p=setInterval(async()=>{(await $())?.connected&&(clearInterval(p),s&&console.log("Browser listening at 127.0.0.1:9222"),e==="zillow"?await U():e==="redfin"&&(await I(),await N()))},1e3);s&&console.log(`Server listening at ${u}:${n}`)}),d=()=>(o.close(async p=>{const a=await N();s&&(console.log(a),console.log("server closed")),process.exit(p?1:0)}),{status:"shutdown"});return r.get("/server",(p,a)=>{try{a.send({running:!0})}catch(t){a.send(t)}}),r.post("/browser/launch",async(p,a)=>{try{const t=await T();a.send({browser:t})}catch(t){a.send(t)}}),r.post("/browser/open",async(p,a)=>{try{const{url:t}=p?.body??{},z=await S(t);a.send({browser:z})}catch(t){a.send(t)}}),r.get("/cookie",async(p,a)=>{try{const t=await A();a.send({cookie:t})}catch(t){a.send(t)}}),r.post("/cookie/save",async(p,a)=>{try{const t=await U();a.send({cookie:t})}catch(t){a.send(t)}}),r.post("/cookie/redfin/save",async(p,a)=>{try{const t=await I();a.send({cookie:t})}catch(t){a.send(t)}}),r.post("/browser/close",async(p,a)=>{try{const t=await P();a.send({browser:t})}catch(t){a.send(t)}}),r.post("/server/shutdown",(p,a)=>{try{const t=d();a.send({server:t})}catch(t){a.send(t)}}),process.on("SIGINT",d),process.on("SIGTERM",d),r}export{A as a,G as b,P as c,I as d,U as e,$ as g,T as l,S as o,ae as r,N as s,te as w};
|