@rent-scraper/browser-server 1.0.22 → 1.0.23

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.DYL0km7i.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{r}from"../shared/browser-server.q0zB05AI.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
@@ -7,6 +7,7 @@ import * as http from 'http';
7
7
  import { ParsedQs } from '/Users/maxwell/Sites/rent-brigade/rent-scraper/node_modules/@types/qs/index.d.ts';
8
8
  import { Options, Ranges, Result } from '/Users/maxwell/Sites/rent-brigade/rent-scraper/node_modules/@types/range-parser/index.d.ts';
9
9
 
10
+ declare const waitForBrowser: (timeoutMs?: number) => Promise<void>;
10
11
  declare const getBrowser: () => Promise<puppeteer.Browser | null>;
11
12
  declare const closeBrowser: () => Promise<void>;
12
13
  declare const launchBrowser: (source?: ListingsSource) => Promise<{
@@ -1249,4 +1250,4 @@ interface Express extends Application {
1249
1250
 
1250
1251
  declare function runBrowserServer(source?: ListingsSource): Express;
1251
1252
 
1252
- export { closeBrowser, getBrowser, getRedfinCookie, getZillowCookie, launchBrowser, openBrowser, runBrowserServer, runConfirmBrowserLaunch, saveRedfinCookie, saveZillowCookie, shutdownBrowser };
1253
+ export { closeBrowser, getBrowser, getRedfinCookie, getZillowCookie, launchBrowser, openBrowser, runBrowserServer, runConfirmBrowserLaunch, saveRedfinCookie, saveZillowCookie, shutdownBrowser, waitForBrowser };
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}from"./shared/browser-server.DYL0km7i.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};
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.q0zB05AI.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 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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rent-scraper/browser-server",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
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/api": "1.0.22",
30
- "@rent-scraper/utils": "1.0.22"
29
+ "@rent-scraper/utils": "1.0.23",
30
+ "@rent-scraper/api": "1.0.23"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/express": "^5.0.3",
package/src/browser.ts CHANGED
@@ -43,6 +43,19 @@ const findNativeBrowser = async (): Promise<string | null> => {
43
43
 
44
44
  const wsChromeEndpointurl = 'http://127.0.0.1:9222/json/version'
45
45
 
46
+ export const waitForBrowser = async (timeoutMs = 15000): Promise<void> => {
47
+ const start = Date.now()
48
+ while (Date.now() - start < timeoutMs) {
49
+ try {
50
+ await puppeteer.connect({ browserURL: wsChromeEndpointurl })
51
+ return
52
+ } catch {
53
+ await new Promise(resolve => setTimeout(resolve, 500))
54
+ }
55
+ }
56
+ throw new Error('timed out waiting for browser')
57
+ }
58
+
46
59
  export const getBrowser = async () => {
47
60
  try {
48
61
  const browser = await puppeteer.connect({
@@ -1 +0,0 @@
1
- import L from"express";import S from"puppeteer";import{mkdtemp as j,access as J}from"fs/promises";import{exec as Q}from"child_process";import{tmpdir as V}from"os";import X from"path";import{checkForConfigFile as Y,waitForConfigFile as x,updateConfigFile as q}from"@rent-scraper/utils/config";import{parseError as D}from"@rent-scraper/utils";const k={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"]},ee=async()=>{const e=k[process.platform]??[];for(const r of e)try{return await J(r),r}catch{}return null},oe="http://127.0.0.1:9222/json/version",$=async()=>{try{return await S.connect({browserURL:oe})}catch{return null}},y=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 Y(e)||await x(e);const r=await j(X.join(V(),"chrome-remote-")),f=await ee();if(console.log(`launching browser: ${f??"bundled chromium"}`),f)Q(`"${f}" --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 S.launch({headless:!1,args:n,dumpio:!1})}return{status:"launched"}},P=async e=>{const r=await $();if(r){const f=e,n=(await r.pages())?.[0]??await r.newPage();return(await n.title()).includes("denied")||await n.goto(f,{waitUntil:"load"}),{status:"opened"}}else return{status:"not connected"}},N=async()=>{const e=await $();return e?(await e.close(),{status:"closed"}):{status:"not connected"}},H="http://127.0.0.1:9222/json/version",F=async(e=0)=>{const r=await S.connect({browserURL:H});e===0&&await P("https://www.zillow.com/homes/for_rent/");const f=await r.pages();if((f?.[0]?await f[0].title():"").includes("Access to this page has been denied"))return await new Promise(s=>setTimeout(s,2e3)),await F(e+1);const n=(await r.cookies()).filter(s=>s.domain?.includes("zillow.com"));return n.some(s=>s.name==="_pxvid")?(await y(),n.map(s=>`${s.name}=${s.value}`).join("; ")):(console.log("refetching zillow cookie"),await new Promise(s=>setTimeout(s,2e3)),await F(e+1))},G=async(e=0)=>{const r=await S.connect({browserURL:H});e===0&&(await P("https://www.redfin.com"),await new Promise(o=>setTimeout(o,3e3)));const f=await r.pages(),n=f?.[0]?await f[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 y(),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 q("redfin",{redfinCookie:e})}catch(e){const{status:r,message:f}=D(e);console.error(r,f)}},U=async()=>{try{const e=await F();e&&await q("zillow",{zillowCookie:e})}catch(e){const{status:r,message:f}=D(e);console.error(r,f)}};function te(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Z,W;function ne(){if(W)return Z;W=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 f(n,s){return s==="constructor"&&typeof n[s]=="function"||s==="__proto__"}return Z=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 A(i,w,B){for(var l=i,O=0;O<w.length-1;O++){var C=w[O];if(f(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];f(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;A(t,i.split("."),l),(d[i]||[]).forEach(function(O){A(t,O.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],u,v;if(/^--.+=/.test(c)){var K=c.match(/^--([^=]+)=([\s\S]*)$/);u=K[1];var R=K[2];o.bools[u]&&(R=R!=="false"),h(u,R,c)}else if(/^--no-.+/.test(c))u=c.match(/^--no-(.+)/)[1],h(u,!1,c);else if(/^--.+/.test(c))u=c.match(/^--(.+)/)[1],v=n[m+1],v!==void 0&&!/^(-|--)[^-]/.test(v)&&!o.bools[u]&&!o.allBools&&(!d[u]||!p(u))?(h(u,v,c),m+=1):/^(true|false)$/.test(v)?(h(u,v==="true",c),m+=1):h(u,o.strings[u]?"":!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)}u=c.slice(-1)[0],!_&&u!=="-"&&(n[m+1]&&!/^(-|--)[^-]/.test(n[m+1])&&!o.bools[u]&&(!d[u]||!p(u))?(h(u,n[m+1],c),m+=1):n[m+1]&&/^(true|false)$/.test(n[m+1])?(h(u,n[m+1]==="true",c),m+=1):h(u,o.strings[u]?"":!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("."))||(A(t,i.split("."),a[i]),(d[i]||[]).forEach(function(w){A(t,w.split("."),a[i])}))}),s["--"]?t["--"]=M.slice():M.forEach(function(i){t._.push(i)}),t},Z}var se=ne();const re=te(se);function ie(e="zillow"){const r=L(),f=process.env.HOST??"127.0.0.1",n=process.env.PORT??8082;r.use(L.json());const s=re(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 ${f}:${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 P(t);a.send({browser:z})}catch(t){a.send(t)}}),r.get("/cookie",async(p,a)=>{try{const t=await F();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 y();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{F as a,G as b,y as c,I as d,U as e,$ as g,T as l,P as o,ie as r,N as s};