@rent-scraper/browser-server 1.0.28 → 1.0.29
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.BZ8vwfSV.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,14 +22,10 @@ declare const shutdownBrowser: () => Promise<{
|
|
|
22
22
|
|
|
23
23
|
declare function runConfirmBrowserLaunch(): Promise<undefined>;
|
|
24
24
|
|
|
25
|
-
declare const getZillowCookie: (attempt?: number
|
|
26
|
-
onCaptcha?: () => Promise<void>;
|
|
27
|
-
}) => Promise<string | undefined>;
|
|
25
|
+
declare const getZillowCookie: (attempt?: number) => Promise<string | undefined>;
|
|
28
26
|
declare const getRedfinCookie: (attempt?: number) => Promise<string | undefined>;
|
|
29
27
|
declare const saveRedfinCookie: () => Promise<void>;
|
|
30
|
-
declare const saveZillowCookie: (
|
|
31
|
-
onCaptcha?: () => Promise<void>;
|
|
32
|
-
}) => Promise<void>;
|
|
28
|
+
declare const saveZillowCookie: () => Promise<void>;
|
|
33
29
|
|
|
34
30
|
// This extracts the core definitions from express to prevent a circular dependency between express and serve-static
|
|
35
31
|
|
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.BZ8vwfSV.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 X}from"child_process";import{tmpdir as Y}from"os";import k from"path";import{checkForConfigFile as oo,waitForConfigFile as eo,getValueFromConfigFile as to,updateConfigFile as K}from"@rent-scraper/utils/config";import{parseError as q}from"@rent-scraper/utils";const H={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"]},V=async()=>{const e=H[process.platform]??[];for(const r of e)try{return await Q(r),r}catch{}return null},W="http://127.0.0.1:9222/json/version",no=async(e=15e3)=>{const r=Date.now();for(;Date.now()-r<e;)try{await O.connect({browserURL:W});return}catch{await new Promise(f=>setTimeout(f,500))}throw new Error("timed out waiting for browser")},E=async()=>{try{return await O.connect({browserURL:W})}catch{return null}},A=async()=>{const e=await(await E())?.pages();e&&await Promise.all(e.map(r=>r.close()))},T=async(e="zillow")=>{if(await E())return{status:"already launched"};await oo(e)||await eo(e);const r=await J(k.join(Y(),"chrome-remote-")),f=await to(e,"browser"),n=f?(H[process.platform]??[]).find(s=>s.toLowerCase().includes(f.toLowerCase()))??await V():await V();if(console.log(`launching browser: ${n??"bundled chromium"}`),n)X(`"${n}" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir="${r}"`,s=>{s&&console.error(`Error: ${s.message}`)});else{const s=["--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:s,dumpio:!1})}return{status:"launched"}},S=async e=>{const r=await E();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 E();return e?(await e.close(),{status:"closed"}):{status:"not connected"}},j="http://127.0.0.1:9222/json/version",P=async(e=0)=>{const r=await O.connect({browserURL:j});e===0&&await S("https://www.zillow.com/homes/for_rent/");const f=await r.cookies(),[n]=f.filter(o=>o.name==="_pxvid"),[s]=f.filter(o=>o.name==="_px3");return n?(await A(),[n,s].filter(Boolean).map(o=>`${o.name}=${o.value}`).join("; ")):(console.log("refetching zillow cookie"),await new Promise(o=>setTimeout(o,2e3)),await P(e+1))},G=async(e=0)=>{const r=await O.connect({browserURL:j});e===0&&(await S("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 A(),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:f}=q(e);console.error(r,f)}},L=async()=>{try{const e={zillowCookie:await P()??{}};await K("zillow",e)}catch(e){const{status:r,message:f}=q(e);console.error(r,f)}};function ro(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var U,x;function so(){if(x)return U;x=1;function e(n,s){var o=n;s.slice(0,-1).forEach(function(d){o=o[d]||{}});var p=s[s.length-1];return p 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 U=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 p={};function d(i){return p[i].some(function(w){return o.bools[w]})}Object.keys(s.alias||{}).forEach(function(i){p[i]=[].concat(s.alias[i]),p[i].forEach(function(w){p[w]=[i].concat(p[i].filter(function(B){return w!==B}))})}),[].concat(s.string).filter(Boolean).forEach(function(i){o.strings[i]=!0,p[i]&&[].concat(p[i]).forEach(function(w){o.strings[w]=!0})});var a=s.default||{},t={_:[]};function M(i,w){return o.allBools&&/^--[^=]+$/.test(w)||o.strings[i]||o.bools[i]||p[i]}function _(i,w,B){for(var l=i,F=0;F<w.length-1;F++){var C=w[F];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 $=w[w.length-1];f(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(i,w,B){if(!(B&&o.unknownFn&&!M(i,B)&&o.unknownFn(B)===!1)){var l=!o.strings[i]&&r(w)?Number(w):w;_(t,i.split("."),l),(p[i]||[]).forEach(function(F){_(t,F.split("."),l)})}}Object.keys(o.bools).forEach(function(i){h(i,a[i]===void 0?!1:a[i])});var R=[];n.indexOf("--")!==-1&&(R=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 D=c.match(/^--([^=]+)=([\s\S]*)$/);u=D[1];var z=D[2];o.bools[u]&&(z=z!=="false"),h(u,z,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&&(!p[u]||!d(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(""),y=!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),y=!0;break}if(/[A-Za-z]/.test(g[b])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(v)){h(g[b],v,c),y=!0;break}if(g[b+1]&&g[b+1].match(/\W/)){h(g[b],c.slice(b+2),c),y=!0;break}else h(g[b],o.strings[g[b]]?"":!0,c)}u=c.slice(-1)[0],!y&&u!=="-"&&(n[m+1]&&!/^(-|--)[^-]/.test(n[m+1])&&!o.bools[u]&&(!p[u]||!d(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("."))||(_(t,i.split("."),a[i]),(p[i]||[]).forEach(function(w){_(t,w.split("."),a[i])}))}),s["--"]?t["--"]=R.slice():R.forEach(function(i){t._.push(i)}),t},U}var io=so();const ao=ro(io);function co(e="zillow"){const r=Z(),f=process.env.HOST??"127.0.0.1",n=process.env.PORT??8082;r.use(Z.json());const s=ao(process.argv.slice(2)).debug,o=r.listen(Number(n),async()=>{await T(e);const d=setInterval(async()=>{(await E())?.connected&&(clearInterval(d),s&&console.log("Browser listening at 127.0.0.1:9222"),e==="zillow"?await L():e==="redfin"&&(await I(),await N()))},1e3);s&&console.log(`Server listening at ${f}:${n}`)}),p=()=>(o.close(async d=>{const a=await N();s&&(console.log(a),console.log("server closed")),process.exit(d?1:0)}),{status:"shutdown"});return r.get("/server",(d,a)=>{try{a.send({running:!0})}catch(t){a.send(t)}}),r.post("/browser/launch",async(d,a)=>{try{const t=await T();a.send({browser:t})}catch(t){a.send(t)}}),r.post("/browser/open",async(d,a)=>{try{const{url:t}=d?.body??{},M=await S(t);a.send({browser:M})}catch(t){a.send(t)}}),r.get("/cookie",async(d,a)=>{try{const t=await P();a.send({cookie:t})}catch(t){a.send(t)}}),r.post("/cookie/save",async(d,a)=>{try{const t=await L();a.send({cookie:t})}catch(t){a.send(t)}}),r.post("/cookie/redfin/save",async(d,a)=>{try{const t=await I();a.send({cookie:t})}catch(t){a.send(t)}}),r.post("/browser/close",async(d,a)=>{try{const t=await A();a.send({browser:t})}catch(t){a.send(t)}}),r.post("/server/shutdown",(d,a)=>{try{const t=p();a.send({server:t})}catch(t){a.send(t)}}),process.on("SIGINT",p),process.on("SIGTERM",p),r}export{P as a,G as b,A as c,I as d,L as e,E as g,T as l,S as o,co as r,N as s,no 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.29",
|
|
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.29",
|
|
30
|
+
"@rent-scraper/api": "1.0.29"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/express": "^5.0.3",
|
package/src/browser.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { access, mkdtemp } from 'fs/promises'
|
|
|
3
3
|
import { exec } from 'child_process'
|
|
4
4
|
import { tmpdir } from 'os'
|
|
5
5
|
import path from 'path'
|
|
6
|
-
import { checkForConfigFile, waitForConfigFile } from '@rent-scraper/utils/config'
|
|
6
|
+
import { checkForConfigFile, waitForConfigFile, getValueFromConfigFile } from '@rent-scraper/utils/config'
|
|
7
7
|
import type { ListingsSource } from '@rent-scraper/api'
|
|
8
8
|
|
|
9
9
|
const nativeBrowserPaths: Partial<Record<NodeJS.Platform, string[]>> = {
|
|
@@ -82,7 +82,10 @@ export const launchBrowser = async (source = 'zillow' as ListingsSource) => {
|
|
|
82
82
|
await waitForConfigFile(source)
|
|
83
83
|
}
|
|
84
84
|
const userDataDir = await mkdtemp(path.join(tmpdir(), 'chrome-remote-'))
|
|
85
|
-
const
|
|
85
|
+
const browserPref = await getValueFromConfigFile(source, 'browser') as string | null
|
|
86
|
+
const nativePath = browserPref
|
|
87
|
+
? (nativeBrowserPaths[process.platform] ?? []).find(p => p.toLowerCase().includes(browserPref.toLowerCase())) ?? await findNativeBrowser()
|
|
88
|
+
: await findNativeBrowser()
|
|
86
89
|
console.log(`launching browser: ${nativePath ?? 'bundled chromium'}`)
|
|
87
90
|
if (nativePath) {
|
|
88
91
|
exec(`"${nativePath}" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir="${userDataDir}"`, (error) => {
|
package/src/cookie.ts
CHANGED
|
@@ -5,29 +5,21 @@ 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
|
|
8
|
+
export const getZillowCookie = async (attempt = 0): Promise<string | undefined> => {
|
|
9
9
|
const browser = await puppeteer.connect({
|
|
10
10
|
browserURL: wsChromeEndpointurl,
|
|
11
11
|
})
|
|
12
12
|
if (attempt === 0) {
|
|
13
13
|
await openBrowser('https://www.zillow.com/homes/for_rent/')
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
const title = pages?.[0] ? await pages[0].title() : ''
|
|
17
|
-
if (title.includes('Access to this page has been denied')) {
|
|
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)
|
|
24
|
-
}
|
|
15
|
+
|
|
25
16
|
const allCookies = await browser.cookies()
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
17
|
+
const [pxvid] = (allCookies).filter(cookie => cookie.name === '_pxvid')
|
|
18
|
+
const [px3] = (allCookies).filter(cookie => cookie.name === '_px3')
|
|
19
|
+
|
|
20
|
+
if (pxvid) {
|
|
29
21
|
await closeBrowser()
|
|
30
|
-
return
|
|
22
|
+
return [pxvid, px3].filter(Boolean).map(c => `${c.name}=${c.value}`).join('; ')
|
|
31
23
|
} else {
|
|
32
24
|
console.log('refetching zillow cookie')
|
|
33
25
|
await new Promise(resolve => setTimeout(resolve, 2000))
|
|
@@ -68,12 +60,16 @@ export const saveRedfinCookie = async () => {
|
|
|
68
60
|
}
|
|
69
61
|
}
|
|
70
62
|
|
|
71
|
-
export const saveZillowCookie = async (
|
|
63
|
+
export const saveZillowCookie = async () => {
|
|
72
64
|
try {
|
|
73
|
-
const zillowCookie = await getZillowCookie(
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
const zillowCookie = await getZillowCookie() ?? {}
|
|
66
|
+
|
|
67
|
+
const data = {
|
|
68
|
+
zillowCookie,
|
|
76
69
|
}
|
|
70
|
+
|
|
71
|
+
// update config file
|
|
72
|
+
await updateConfigFile('zillow', data)
|
|
77
73
|
} catch (error: any) {
|
|
78
74
|
const { status, message } = parseError(error)
|
|
79
75
|
console.error(status, message)
|
|
@@ -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 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};
|