@rent-scraper/browser-server 1.0.19 → 1.0.20
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.B5TmJ8LU.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,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.B5TmJ8LU.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 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};
|
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.20",
|
|
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/utils": "1.0.20",
|
|
30
|
+
"@rent-scraper/api": "1.0.20"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/express": "^5.0.3",
|
package/src/browser.ts
CHANGED
|
@@ -1,8 +1,46 @@
|
|
|
1
1
|
import puppeteer from 'puppeteer'
|
|
2
|
+
import { access, mkdtemp } from 'fs/promises'
|
|
2
3
|
import { exec } from 'child_process'
|
|
3
|
-
import {
|
|
4
|
+
import { tmpdir } from 'os'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
import { checkForConfigFile, waitForConfigFile } from '@rent-scraper/utils/config'
|
|
4
7
|
import type { ListingsSource } from '@rent-scraper/api'
|
|
5
8
|
|
|
9
|
+
const nativeBrowserPaths: Partial<Record<NodeJS.Platform, string[]>> = {
|
|
10
|
+
darwin: [
|
|
11
|
+
'/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',
|
|
12
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
13
|
+
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
|
14
|
+
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
|
|
15
|
+
],
|
|
16
|
+
linux: [
|
|
17
|
+
'/usr/bin/brave-browser',
|
|
18
|
+
'/usr/bin/google-chrome',
|
|
19
|
+
'/usr/bin/google-chrome-stable',
|
|
20
|
+
'/usr/bin/chromium-browser',
|
|
21
|
+
'/usr/bin/chromium',
|
|
22
|
+
'/snap/bin/chromium',
|
|
23
|
+
],
|
|
24
|
+
win32: [
|
|
25
|
+
'C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe',
|
|
26
|
+
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
27
|
+
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
28
|
+
],
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const findNativeBrowser = async (): Promise<string | null> => {
|
|
32
|
+
const paths = nativeBrowserPaths[process.platform] ?? []
|
|
33
|
+
for (const browserPath of paths) {
|
|
34
|
+
try {
|
|
35
|
+
await access(browserPath)
|
|
36
|
+
return browserPath
|
|
37
|
+
} catch {
|
|
38
|
+
// not found, try next
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
|
|
6
44
|
const wsChromeEndpointurl = 'http://127.0.0.1:9222/json/version'
|
|
7
45
|
|
|
8
46
|
export const getBrowser = async () => {
|
|
@@ -26,20 +64,28 @@ export const launchBrowser = async (source = 'zillow' as ListingsSource) => {
|
|
|
26
64
|
const browser = await getBrowser()
|
|
27
65
|
if (browser) {
|
|
28
66
|
return { status: 'already launched' }
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
67
|
+
}
|
|
68
|
+
if (!await checkForConfigFile(source)) {
|
|
69
|
+
await waitForConfigFile(source)
|
|
70
|
+
}
|
|
71
|
+
const userDataDir = await mkdtemp(path.join(tmpdir(), 'chrome-remote-'))
|
|
72
|
+
const nativePath = await findNativeBrowser()
|
|
73
|
+
console.log(`launching browser: ${nativePath ?? 'bundled chromium'}`)
|
|
74
|
+
if (nativePath) {
|
|
75
|
+
exec(`"${nativePath}" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir="${userDataDir}"`, (error) => {
|
|
76
|
+
if (error) console.error(`Error: ${error.message}`)
|
|
40
77
|
})
|
|
41
|
-
|
|
78
|
+
} else {
|
|
79
|
+
const args = [
|
|
80
|
+
'--remote-debugging-port=9222',
|
|
81
|
+
'--no-first-run',
|
|
82
|
+
'--no-default-browser-check',
|
|
83
|
+
`--user-data-dir=${userDataDir}`,
|
|
84
|
+
...(process.platform === 'linux' ? ['--no-sandbox', '--disable-setuid-sandbox'] : []),
|
|
85
|
+
]
|
|
86
|
+
await puppeteer.launch({ headless: false, args, dumpio: false })
|
|
42
87
|
}
|
|
88
|
+
return { status: 'launched' }
|
|
43
89
|
}
|
|
44
90
|
|
|
45
91
|
export const openBrowser = async (url: string) => {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import L from"express";import T from"puppeteer";import{exec as J}from"child_process";import{checkForConfigFile as q,waitForConfigFile as Q,getValueFromConfigFile as X,updateConfigFile as D}from"@rent-scraper/utils/config";import{parseError as H}from"@rent-scraper/utils";const Y="http://127.0.0.1:9222/json/version",_=async()=>{try{return await T.connect({browserURL:Y})}catch{return null}},A=async()=>{const o=await(await _())?.pages();o&&await Promise.all(o.map(i=>i.close()))},N=async(o="zillow")=>{if(await _())return{status:"already launched"};{await q(o)||await Q(o),await q(o);const i=await X(o,"browser")==="brave"?"/Applications/Brave\\ Browser.app/Contents/MacOS/Brave\\ Browser":"/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome";return J(`${i} --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir=$(mktemp -d -t 'chrome-remote_data_dir')`,f=>{f&&console.error(`Error: ${f.message}`)}),{status:"launched"}}},S=async o=>{const i=await _();if(i){const f=o,s=(await i.pages())?.[0]??await i.newPage();return(await s.title()).includes("denied")||await s.goto(f,{waitUntil:"load"}),{status:"opened"}}else return{status:"not connected"}},I=async()=>{const o=await _();return o?(await o.close(),{status:"closed"}):{status:"not connected"}},V="http://127.0.0.1:9222/json/version",F=async(o=0)=>{const i=await T.connect({browserURL:V});o===0&&await S("https://www.zillow.com/homes/for_rent/");const f=await i.pages();if((f?.[0]?await f[0].title():"").includes("Access to this page has been denied"))return await new Promise(r=>setTimeout(r,2e3)),await F(o+1);const[s]=(await i.cookies()).filter(r=>r.name==="_pxvid");return s?(await A(),s):(console.log("refetching zillow cookie"),await new Promise(r=>setTimeout(r,2e3)),await F(o+1))},M=async(o=0)=>{const i=await T.connect({browserURL:V});o===0&&(await S("https://www.redfin.com"),await new Promise(t=>setTimeout(t,3e3)));const f=await i.pages(),s=f?.[0]?await f[0].title():"",r=(await i.cookies()).filter(t=>t.domain.includes("redfin.com"));return r.some(t=>t.name==="aws-waf-token")&&s.includes("Redfin")?(await A(),r.map(t=>`${t.name}=${t.value}`).join("; ")):(console.log("refetching redfin cookie"),await new Promise(t=>setTimeout(t,2e3)),await M(o+1))},G=async()=>{try{const o=await M();o&&await D("redfin",{redfinCookie:o})}catch(o){const{status:i,message:f}=H(o);console.error(i,f)}},U=async()=>{try{const{name:o,value:i}=await F()??{},f={zillowCookie:`${o}=${i}`};await D("zillow",f)}catch(o){const{status:i,message:f}=H(o);console.error(i,f)}};function j(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var Z,W;function x(){if(W)return Z;W=1;function o(s,r){var t=s;r.slice(0,-1).forEach(function(p){t=t[p]||{}});var d=r[r.length-1];return d in t}function i(s){return typeof s=="number"||/^0x[0-9a-f]+$/i.test(s)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(s)}function f(s,r){return r==="constructor"&&typeof s[r]=="function"||r==="__proto__"}return Z=function(s,r){r||(r={});var t={bools:{},strings:{},unknownFn:null};typeof r.unknown=="function"&&(t.unknownFn=r.unknown),typeof r.boolean=="boolean"&&r.boolean?t.allBools=!0:[].concat(r.boolean).filter(Boolean).forEach(function(n){t.bools[n]=!0});var d={};function p(n){return d[n].some(function(w){return t.bools[w]})}Object.keys(r.alias||{}).forEach(function(n){d[n]=[].concat(r.alias[n]),d[n].forEach(function(w){d[w]=[n].concat(d[n].filter(function(E){return w!==E}))})}),[].concat(r.string).filter(Boolean).forEach(function(n){t.strings[n]=!0,d[n]&&[].concat(d[n]).forEach(function(w){t.strings[w]=!0})});var a=r.default||{},e={_:[]};function z(n,w){return t.allBools&&/^--[^=]+$/.test(w)||t.strings[n]||t.bools[n]||d[n]}function O(n,w,E){for(var l=n,$=0;$<w.length-1;$++){var B=w[$];if(f(l,B))return;l[B]===void 0&&(l[B]={}),(l[B]===Object.prototype||l[B]===Number.prototype||l[B]===String.prototype)&&(l[B]={}),l[B]===Array.prototype&&(l[B]=[]),l=l[B]}var C=w[w.length-1];f(l,C)||((l===Object.prototype||l===Number.prototype||l===String.prototype)&&(l={}),l===Array.prototype&&(l=[]),l[C]===void 0||t.bools[C]||typeof l[C]=="boolean"?l[C]=E:Array.isArray(l[C])?l[C].push(E):l[C]=[l[C],E])}function h(n,w,E){if(!(E&&t.unknownFn&&!z(n,E)&&t.unknownFn(E)===!1)){var l=!t.strings[n]&&i(w)?Number(w):w;O(e,n.split("."),l),(d[n]||[]).forEach(function($){O(e,$.split("."),l)})}}Object.keys(t.bools).forEach(function(n){h(n,a[n]===void 0?!1:a[n])});var P=[];s.indexOf("--")!==-1&&(P=s.slice(s.indexOf("--")+1),s=s.slice(0,s.indexOf("--")));for(var m=0;m<s.length;m++){var c=s[m],u,v;if(/^--.+=/.test(c)){var K=c.match(/^--([^=]+)=([\s\S]*)$/);u=K[1];var R=K[2];t.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=s[m+1],v!==void 0&&!/^(-|--)[^-]/.test(v)&&!t.bools[u]&&!t.allBools&&(!d[u]||!p(u))?(h(u,v,c),m+=1):/^(true|false)$/.test(v)?(h(u,v==="true",c),m+=1):h(u,t.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],t.strings[g[b]]?"":!0,c)}u=c.slice(-1)[0],!y&&u!=="-"&&(s[m+1]&&!/^(-|--)[^-]/.test(s[m+1])&&!t.bools[u]&&(!d[u]||!p(u))?(h(u,s[m+1],c),m+=1):s[m+1]&&/^(true|false)$/.test(s[m+1])?(h(u,s[m+1]==="true",c),m+=1):h(u,t.strings[u]?"":!0,c))}else if((!t.unknownFn||t.unknownFn(c)!==!1)&&e._.push(t.strings._||!i(c)?c:Number(c)),r.stopEarly){e._.push.apply(e._,s.slice(m+1));break}}return Object.keys(a).forEach(function(n){o(e,n.split("."))||(O(e,n.split("."),a[n]),(d[n]||[]).forEach(function(w){O(e,w.split("."),a[n])}))}),r["--"]?e["--"]=P.slice():P.forEach(function(n){e._.push(n)}),e},Z}var k=x();const tt=j(k);function et(o="zillow"){const i=L(),f=process.env.HOST??"127.0.0.1",s=process.env.PORT??8082;i.use(L.json());const r=tt(process.argv.slice(2)).debug,t=i.listen(Number(s),async()=>{await N(o);const p=setInterval(async()=>{(await _())?.connected&&(clearInterval(p),r&&console.log("Browser listening at 127.0.0.1:9222"),o==="zillow"?await U():o==="redfin"&&(await G(),await I()))},1e3);r&&console.log(`Server listening at ${f}:${s}`)}),d=()=>(t.close(async p=>{const a=await I();r&&(console.log(a),console.log("server closed")),process.exit(p?1:0)}),{status:"shutdown"});return i.get("/server",(p,a)=>{try{a.send({running:!0})}catch(e){a.send(e)}}),i.post("/browser/launch",async(p,a)=>{try{const e=await N();a.send({browser:e})}catch(e){a.send(e)}}),i.post("/browser/open",async(p,a)=>{try{const{url:e}=p?.body??{},z=await S(e);a.send({browser:z})}catch(e){a.send(e)}}),i.get("/cookie",async(p,a)=>{try{const e=await F();a.send({cookie:e})}catch(e){a.send(e)}}),i.post("/cookie/save",async(p,a)=>{try{const e=await U();a.send({cookie:e})}catch(e){a.send(e)}}),i.post("/cookie/redfin/save",async(p,a)=>{try{const e=await G();a.send({cookie:e})}catch(e){a.send(e)}}),i.post("/browser/close",async(p,a)=>{try{const e=await A();a.send({browser:e})}catch(e){a.send(e)}}),i.post("/server/shutdown",(p,a)=>{try{const e=d();a.send({server:e})}catch(e){a.send(e)}}),process.on("SIGINT",d),process.on("SIGTERM",d),i}export{F as a,M as b,A as c,G as d,U as e,_ as g,N as l,S as o,et as r,I as s};
|