@rent-scraper/browser-server 1.0.20 → 1.0.22
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.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();
|
package/dist/index.d.mts
CHANGED
|
@@ -21,10 +21,7 @@ declare const shutdownBrowser: () => Promise<{
|
|
|
21
21
|
|
|
22
22
|
declare function runConfirmBrowserLaunch(): Promise<undefined>;
|
|
23
23
|
|
|
24
|
-
declare const getZillowCookie: (attempt?: number) => Promise<
|
|
25
|
-
name: string;
|
|
26
|
-
value: string;
|
|
27
|
-
} | undefined>;
|
|
24
|
+
declare const getZillowCookie: (attempt?: number) => Promise<string | undefined>;
|
|
28
25
|
declare const getRedfinCookie: (attempt?: number) => Promise<string | undefined>;
|
|
29
26
|
declare const saveRedfinCookie: () => Promise<void>;
|
|
30
27
|
declare const saveZillowCookie: () => Promise<void>;
|
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.
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
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.22",
|
|
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.22",
|
|
30
|
+
"@rent-scraper/utils": "1.0.22"
|
|
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<
|
|
8
|
+
export const getZillowCookie = async (attempt = 0): Promise<string | undefined> => {
|
|
9
9
|
const browser = await puppeteer.connect({
|
|
10
10
|
browserURL: wsChromeEndpointurl,
|
|
11
11
|
})
|
|
@@ -18,10 +18,12 @@ export const getZillowCookie = async (attempt = 0): Promise<{ name: string, valu
|
|
|
18
18
|
await new Promise(resolve => setTimeout(resolve, 2000))
|
|
19
19
|
return await getZillowCookie(attempt + 1)
|
|
20
20
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
21
|
+
const allCookies = await browser.cookies()
|
|
22
|
+
const zillowCookies = allCookies.filter(c => c.domain?.includes('zillow.com'))
|
|
23
|
+
const hasPxvid = zillowCookies.some(c => c.name === '_pxvid')
|
|
24
|
+
if (hasPxvid) {
|
|
23
25
|
await closeBrowser()
|
|
24
|
-
return
|
|
26
|
+
return zillowCookies.map(c => `${c.name}=${c.value}`).join('; ')
|
|
25
27
|
} else {
|
|
26
28
|
console.log('refetching zillow cookie')
|
|
27
29
|
await new Promise(resolve => setTimeout(resolve, 2000))
|
|
@@ -64,15 +66,10 @@ export const saveRedfinCookie = async () => {
|
|
|
64
66
|
|
|
65
67
|
export const saveZillowCookie = async () => {
|
|
66
68
|
try {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const data = {
|
|
71
|
-
zillowCookie,
|
|
69
|
+
const zillowCookie = await getZillowCookie()
|
|
70
|
+
if (zillowCookie) {
|
|
71
|
+
await updateConfigFile('zillow', { zillowCookie })
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
// update config file
|
|
75
|
-
await updateConfigFile('zillow', data)
|
|
76
73
|
} catch (error: any) {
|
|
77
74
|
const { status, message } = parseError(error)
|
|
78
75
|
console.error(status, message)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import L from"express";import S 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 j,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 t=k[process.platform]??[];for(const s of t)try{return await Q(s),s}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 t=await(await $())?.pages();t&&await Promise.all(t.map(s=>s.close()))},T=async(t="zillow")=>{if(await $())return{status:"already launched"};await j(t)||await x(t);const s=await J(Y.join(X(),"chrome-remote-")),u=await ee();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="${s}"`,n=>{n&&console.error(`Error: ${n.message}`)});else{const n=["--remote-debugging-port=9222","--no-first-run","--no-default-browser-check",`--user-data-dir=${s}`,...process.platform==="linux"?["--no-sandbox","--disable-setuid-sandbox"]:[]];await S.launch({headless:!1,args:n,dumpio:!1})}return{status:"launched"}},P=async t=>{const s=await $();if(s){const u=t,n=(await s.pages())?.[0]??await s.newPage();return(await n.title()).includes("denied")||await n.goto(u,{waitUntil:"load"}),{status:"opened"}}else return{status:"not connected"}},N=async()=>{const t=await $();return t?(await t.close(),{status:"closed"}):{status:"not connected"}},H="http://127.0.0.1:9222/json/version",F=async(t=0)=>{const s=await S.connect({browserURL:H});t===0&&await P("https://www.zillow.com/homes/for_rent/");const u=await s.pages();if((u?.[0]?await u[0].title():"").includes("Access to this page has been denied"))return await new Promise(i=>setTimeout(i,2e3)),await F(t+1);const[n]=(await s.cookies()).filter(i=>i.name==="_pxvid");return n?(await y(),n):(console.log("refetching zillow cookie"),await new Promise(i=>setTimeout(i,2e3)),await F(t+1))},G=async(t=0)=>{const s=await S.connect({browserURL:H});t===0&&(await P("https://www.redfin.com"),await new Promise(e=>setTimeout(e,3e3)));const u=await s.pages(),n=u?.[0]?await u[0].title():"",i=(await s.cookies()).filter(e=>e.domain.includes("redfin.com"));return i.some(e=>e.name==="aws-waf-token")&&n.includes("Redfin")?(await y(),i.map(e=>`${e.name}=${e.value}`).join("; ")):(console.log("refetching redfin cookie"),await new Promise(e=>setTimeout(e,2e3)),await G(t+1))},I=async()=>{try{const t=await G();t&&await q("redfin",{redfinCookie:t})}catch(t){const{status:s,message:u}=D(t);console.error(s,u)}},U=async()=>{try{const{name:t,value:s}=await F()??{},u={zillowCookie:`${t}=${s}`};await q("zillow",u)}catch(t){const{status:s,message:u}=D(t);console.error(s,u)}};function te(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Z,W;function ne(){if(W)return Z;W=1;function t(n,i){var e=n;i.slice(0,-1).forEach(function(p){e=e[p]||{}});var d=i[i.length-1];return d in e}function s(n){return typeof n=="number"||/^0x[0-9a-f]+$/i.test(n)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(n)}function u(n,i){return i==="constructor"&&typeof n[i]=="function"||i==="__proto__"}return Z=function(n,i){i||(i={});var e={bools:{},strings:{},unknownFn:null};typeof i.unknown=="function"&&(e.unknownFn=i.unknown),typeof i.boolean=="boolean"&&i.boolean?e.allBools=!0:[].concat(i.boolean).filter(Boolean).forEach(function(r){e.bools[r]=!0});var d={};function p(r){return d[r].some(function(w){return e.bools[w]})}Object.keys(i.alias||{}).forEach(function(r){d[r]=[].concat(i.alias[r]),d[r].forEach(function(w){d[w]=[r].concat(d[r].filter(function(B){return w!==B}))})}),[].concat(i.string).filter(Boolean).forEach(function(r){e.strings[r]=!0,d[r]&&[].concat(d[r]).forEach(function(w){e.strings[w]=!0})});var a=i.default||{},o={_:[]};function M(r,w){return e.allBools&&/^--[^=]+$/.test(w)||e.strings[r]||e.bools[r]||d[r]}function A(r,w,B){for(var l=r,O=0;O<w.length-1;O++){var C=w[O];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||e.bools[E]||typeof l[E]=="boolean"?l[E]=B:Array.isArray(l[E])?l[E].push(B):l[E]=[l[E],B])}function h(r,w,B){if(!(B&&e.unknownFn&&!M(r,B)&&e.unknownFn(B)===!1)){var l=!e.strings[r]&&s(w)?Number(w):w;A(o,r.split("."),l),(d[r]||[]).forEach(function(O){A(o,O.split("."),l)})}}Object.keys(e.bools).forEach(function(r){h(r,a[r]===void 0?!1:a[r])});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 c=n[m],f,v;if(/^--.+=/.test(c)){var K=c.match(/^--([^=]+)=([\s\S]*)$/);f=K[1];var R=K[2];e.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)&&!e.bools[f]&&!e.allBools&&(!d[f]||!p(f))?(h(f,v,c),m+=1):/^(true|false)$/.test(v)?(h(f,v==="true",c),m+=1):h(f,e.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],e.strings[g[b]]?"":!0,c)}f=c.slice(-1)[0],!_&&f!=="-"&&(n[m+1]&&!/^(-|--)[^-]/.test(n[m+1])&&!e.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,e.strings[f]?"":!0,c))}else if((!e.unknownFn||e.unknownFn(c)!==!1)&&o._.push(e.strings._||!s(c)?c:Number(c)),i.stopEarly){o._.push.apply(o._,n.slice(m+1));break}}return Object.keys(a).forEach(function(r){t(o,r.split("."))||(A(o,r.split("."),a[r]),(d[r]||[]).forEach(function(w){A(o,w.split("."),a[r])}))}),i["--"]?o["--"]=z.slice():z.forEach(function(r){o._.push(r)}),o},Z}var se=ne();const re=te(se);function ie(t="zillow"){const s=L(),u=process.env.HOST??"127.0.0.1",n=process.env.PORT??8082;s.use(L.json());const i=re(process.argv.slice(2)).debug,e=s.listen(Number(n),async()=>{await T(t);const p=setInterval(async()=>{(await $())?.connected&&(clearInterval(p),i&&console.log("Browser listening at 127.0.0.1:9222"),t==="zillow"?await U():t==="redfin"&&(await I(),await N()))},1e3);i&&console.log(`Server listening at ${u}:${n}`)}),d=()=>(e.close(async p=>{const a=await N();i&&(console.log(a),console.log("server closed")),process.exit(p?1:0)}),{status:"shutdown"});return s.get("/server",(p,a)=>{try{a.send({running:!0})}catch(o){a.send(o)}}),s.post("/browser/launch",async(p,a)=>{try{const o=await T();a.send({browser:o})}catch(o){a.send(o)}}),s.post("/browser/open",async(p,a)=>{try{const{url:o}=p?.body??{},M=await P(o);a.send({browser:M})}catch(o){a.send(o)}}),s.get("/cookie",async(p,a)=>{try{const o=await F();a.send({cookie:o})}catch(o){a.send(o)}}),s.post("/cookie/save",async(p,a)=>{try{const o=await U();a.send({cookie:o})}catch(o){a.send(o)}}),s.post("/cookie/redfin/save",async(p,a)=>{try{const o=await I();a.send({cookie:o})}catch(o){a.send(o)}}),s.post("/browser/close",async(p,a)=>{try{const o=await y();a.send({browser:o})}catch(o){a.send(o)}}),s.post("/server/shutdown",(p,a)=>{try{const o=d();a.send({server:o})}catch(o){a.send(o)}}),process.on("SIGINT",d),process.on("SIGTERM",d),s}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};
|