diff --git a/pkg/scraper/url.go b/pkg/scraper/url.go index 10a160f40..ddc63a8fb 100644 --- a/pkg/scraper/url.go +++ b/pkg/scraper/url.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "io" + "net" "net/http" "net/url" "os" @@ -87,7 +88,7 @@ func loadURL(ctx context.Context, loadURL string, client *http.Client, scraperCo // func urlFromCDP uses chrome cdp and DOM to load and process the url // if remote is set as true in the scraperConfig it will try to use localhost:9222 // else it will look for google-chrome in path -func urlFromCDP(ctx context.Context, url string, driverOptions scraperDriverOptions, globalConfig GlobalConfig) (io.Reader, error) { +func urlFromCDP(ctx context.Context, urlCDP string, driverOptions scraperDriverOptions, globalConfig GlobalConfig) (io.Reader, error) { if !driverOptions.UseCDP { return nil, fmt.Errorf("url shouldn't be fetched through CDP") @@ -107,6 +108,33 @@ func urlFromCDP(ctx context.Context, url string, driverOptions scraperDriverOpti if isCDPPathHTTP(globalConfig) || isCDPPathWS(globalConfig) { remote := cdpPath + // ------------------------------------------------------------------- + // #1023 + // when chromium is listening over RDP it only accepts requests + // with host headers that are either IPs or `localhost` + cdpURL, err := url.Parse(remote) + if err != nil { + return nil, fmt.Errorf("failed to parse CDP Path: %v", err) + } + hostname := cdpURL.Hostname() + if hostname != "localhost" { + if net.ParseIP(hostname) == nil { // not an IP + addr, err := net.LookupIP(hostname) + if err != nil || len(addr) == 0 { // can not resolve to IP + return nil, fmt.Errorf("CDP: hostname <%s> can not be resolved", hostname) + } + if len(addr[0]) == 0 { // nil IP + return nil, fmt.Errorf("CDP: hostname <%s> resolved to nil", hostname) + } + // addr is a valid IP + // replace the host part of the cdpURL with the IP + cdpURL.Host = strings.Replace(cdpURL.Host, hostname, addr[0].String(), 1) + // use that for remote + remote = cdpURL.String() + } + } + // -------------------------------------------------------------------- + // if CDPPath is http(s) then we need to get the websocket URL if isCDPPathHTTP(globalConfig) { var err error @@ -150,7 +178,7 @@ func urlFromCDP(ctx context.Context, url string, driverOptions scraperDriverOpti setCDPCookies(driverOptions), printCDPCookies(driverOptions, "Cookies found"), network.SetExtraHTTPHeaders(network.Headers(headers)), - chromedp.Navigate(url), + chromedp.Navigate(urlCDP), chromedp.Sleep(sleepDuration), setCDPClicks(driverOptions), chromedp.OuterHTML("html", &res, chromedp.ByQuery), diff --git a/ui/v2.5/src/components/Changelog/versions/v0130.md b/ui/v2.5/src/components/Changelog/versions/v0130.md index 3cd68fee0..f0276b26b 100644 --- a/ui/v2.5/src/components/Changelog/versions/v0130.md +++ b/ui/v2.5/src/components/Changelog/versions/v0130.md @@ -4,6 +4,7 @@ * Show counts on list tabs in Performer, Studio and Tag pages. ([#2169](https://github.com/stashapp/stash/pull/2169)) ### 🐛 Bug fixes +* Resolve CDP hostname if necessary. ([#2174](https://github.com/stashapp/stash/pull/2174)) * Generate sprites for short video files. ([#2167](https://github.com/stashapp/stash/pull/2167)) * Fix stash-box scraping including underscores in ethnicity. ([#2191](https://github.com/stashapp/stash/pull/2191)) * Fix stash-box batch performer task not setting birthdate. ([#2189](https://github.com/stashapp/stash/pull/2189))