projectdiscovery/katana · error

could not get links

Error message

could not get links

What it means

Wrapper error from FindNavigations when b.GetAllElements(linksCSSSelector) (selector "a") fails while enumerating anchor elements. GetAllElements runs the selector in the page via window.getAllElements over CDP; failure is either the eval erroring (context gone, tab closed) or the result failing to unmarshal into []*types.HTMLElement. Link discovery is aborted for the page.

Source

Thrown at pkg/engine/headless/browser/element.go:114

		}

		hash := button.Hash()
		button.MD5Hash = hash

		if _, found := unique[hash]; found {
			continue
		}
		unique[hash] = struct{}{}
		navigations = append(navigations, &types.Action{
			Type:    types.ActionTypeLeftClick,
			Element: button,
		})
	}

	scopeValidator := b.launcher.ScopeValidator()
	links, err := b.GetAllElements(linksCSSSelector)
	if err != nil {
		return nil, errors.Wrap(err, "could not get links")
	}
	info, err := b.Info()
	if err != nil {
		return nil, errors.Wrap(err, "could not get page info")
	}
	for _, link := range links {
		href := link.Attributes["href"]
		if href == "" {
			continue
		}

		resolvedHref, err := resolveURL(info.URL, href)
		if err != nil {
			continue
		}

		u, err := url.Parse(resolvedHref)
		if err != nil {

View on GitHub (pinned to e3e742739c)

Solutions

  1. Ensure the page has finished loading before discovery (wait for load events)
  2. Retry once; context-destroyed errors are transient
  3. Check that injected init scripts (window.getAllElements etc.) run for every document, including iframes/new documents
  4. Update katana to get hardened eval error handling
Defensive patterns

Strategy: fallback

Validate before calling

// verify eval pipeline works with a cheap call first
if _, err := page.GetAllElements("body"); err != nil { return fallbackToHTTPCrawl(page) }

Type guard

func evalHealthy(p *browser.BrowserPage) bool {
    _, err := p.GetAllElements("html")
    return err == nil
}

Try / catch

navs, err := page.FindNavigations()
if err != nil {
    logger.Warn("link discovery failed", slog.String("error", err.Error()))
    return nil // continue crawling other pages
}

Prevention

When it happens

Trigger: 1) Execution context invalidated by an in-page navigation triggered between the earlier discovery steps. 2) Renderer/tab closed or crashed. 3) Missing window.getAllElements injection on this document. 4) Unexpected JSON shape from the eval.

Common situations: Crawling sites with instant client-side redirects (meta refresh/JS), error pages with no proper DOM, resource-constrained CI runs where Chrome tabs get killed.

Related errors


AI-assisted analysis of projectdiscovery/katana@e3e742739c (2026-09-03). Data as JSON: /api/errors/fa9440f9b5ffa9d5. Report an issue: GitHub.