{"record":{"id":"f8f53381930f6796","repo":"projectdiscovery/katana","slug":"could-not-get-event-listeners","errorCode":null,"errorMessage":"could not get event listeners","messagePattern":"could not get event listeners","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/engine/headless/browser/element.go","lineNumber":157,"sourceCode":"\t\t\tcontinue\n\t\t}\n\n\t\thash := link.Hash()\n\t\tlink.MD5Hash = hash\n\n\t\tif _, found := unique[hash]; found {\n\t\t\tcontinue\n\t\t}\n\t\tunique[hash] = struct{}{}\n\t\tnavigations = append(navigations, &types.Action{\n\t\t\tType:    types.ActionTypeLeftClick,\n\t\t\tElement: link,\n\t\t})\n\t}\n\n\teventListeners, err := b.GetEventListeners()\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"could not get event listeners\")\n\t}\n\tfor _, listener := range eventListeners {\n\t\tif _, found := relevantEventListeners[listener.Type]; !found {\n\t\t\tcontinue\n\t\t}\n\t\tif listener.Element == nil {\n\t\t\tcontinue\n\t\t}\n\t\thash := listener.Element.Hash()\n\t\tlistener.Element.MD5Hash = hash\n\t\tif _, found := unique[hash]; found {\n\t\t\tcontinue\n\t\t}\n\t\tunique[hash] = struct{}{}\n\t\tnavigations = append(navigations, types.ActionFromEventListener(listener))\n\t}\n\n\tnavLinks, err := b.GetNavigatedLinks()","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/projectdiscovery/katana/blob/e3e742739c3746f085943ce918fb4e2b8daf6fe6/pkg/engine/headless/browser/element.go#L139-L175","documentation":"Wrapper error from FindNavigations when b.GetEventListeners() fails. GetEventListeners evaluates window.__eventListeners (tolerated failure) and then window.getAllElementsWithEventListeners() (hard failure) plus JSON unmarshaling of the inline listener list; any error in the latter two is wrapped here. Event-listener based action discovery is aborted for the page.","triggerScenarios":"1) window.getAllElementsWithEventListeners helper missing from the document (injection scripts not run on this page/iframe). 2) Execution context destroyed by navigation during discovery. 3) The returned listener JSON does not match the expected element/listeners shape, failing Unmarshal. 4) Tab closed/crashed.","commonSituations":"Crawling SPAs or iframes where init scripts don't cover every document; sites whose inline listeners produce odd serialization; rapid client-side navigation races.","solutions":["Confirm katana's injected helpers run on all frames/documents (update katana if using an old build)","Wait for stable page load before discovery to avoid context races","Retry the page once on transient eval errors","Log-and-skip: treat a single page failure as non-fatal for the whole crawl"],"exampleFix":"// before\nlisteners, err := page.FindNavigations()\nif err != nil { return err }\n// after\nlisteners, err := page.FindNavigations()\nif err != nil {\n    return fmt.Errorf(\"navigation discovery skipped: %w\", err) // or log+continue\n}","handlingStrategy":"try-catch","validationCode":"// probe that injected helpers exist in this document\nif _, err := page.Eval(\"() => typeof window.getAllElementsWithEventListeners === 'function'\"); err != nil {\n    return // helpers missing; discovery will fail\n}","typeGuard":"func helpersInjected(p *browser.BrowserPage) bool {\n    out, err := p.Eval(\"() => typeof window.getAllElementsWithEventListeners\")\n    return err == nil && strings.Contains(out.Value.String(), \"function\")\n}","tryCatchPattern":"navs, err := page.FindNavigations()\nif err != nil {\n    logger.Debug(\"event listener discovery failed\", slog.String(\"error\", err.Error()))\n    return navsFallback // continue with forms/buttons/links only\n}","preventionTips":["Keep katana updated so init scripts cover all frames","Avoid navigating the page while discovery is running","Retry once on transient eval failures","Degrade to non-listener actions instead of failing"],"tags":["headless-browser","event-listeners","crawl"],"backgroundTag":"cdp-evaluation-failed","analyzedSha":"e3e742739c3746f085943ce918fb4e2b8daf6fe6","analyzedAt":"2026-09-03T14:55:13.248Z","contentChangedAt":"2026-09-03T14:55:13.248Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}