Skip to content

Optimize when finding elements to interact with

Problem

During the crawl process, Browser-based DAST searches for subsequent actions to perform. One approach taken is by searching all DOM elements on the page for JavaScript event handlers (e.g. onClick).

The approach used to find event handlers is suboptimal and can be improved.

Evidence

Flamegraph

Purple highlight is Tab.FindInteractables, blue boxes are redundant work

Proposal

Only the elements on the page that have event handlers should be converted to HTML element domain objects (which is expensive).

Implementation plan

  • In Tab.FindInteractables(), stop calling element.ToHTMLElement().Events() > 0 and includeClickable
  • Instead, ask the element if it has click events element.HasClickEventHandler().
    • Internally, this should call GetEventListeners().
    • This avoids the call toHTMLElement in many situations, which is expensive.
    • Before GetEventListeners() is called, return false if the tag name is the same as those listed in includeClickable
  • Convert elements that match to ToHTMLElement and return them.
  • Create a flamegraph after making the changes (see ">Test" in comment), search by "FindInteractables" and ensure the time taken by FindInteractables in the BrowserkCrawler.Process time is smaller than the flamegraph in the issue description. Please post the flamegraph to the issue on completion.
Edited by Cameron Swords