onQuerySelectorAll method

void onQuerySelectorAll(
  1. int? id,
  2. Map<String, dynamic> params
)

https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-querySelectorAll Returns the nodeIds of all elements that match the selector under the given node.

Implementation

void onQuerySelectorAll(int? id, Map<String, dynamic> params) {
  final ctx = dbgContext;
  if (ctx == null) {
    sendToFrontend(id, null);
    return;
  }

  final int? baseNodeId = params['nodeId'];
  final String? selector = params['selector'];
  if (baseNodeId == null || selector == null || selector.isEmpty) {
    sendToFrontend(id, JSONEncodableMap({'nodeIds': <int>[]}));
    return;
  }

  final basePtr = ctx.getTargetIdByNodeId(baseNodeId);
  if (basePtr == null || basePtr == 0) {
    sendToFrontend(id, JSONEncodableMap({'nodeIds': <int>[]}));
    return;
  }

  final Node? baseNode = ctx.getBindingObject(Pointer.fromAddress(basePtr)) as Node?;
  List<Element> matches = const <Element>[];
  try {
    if (baseNode is Element) {
      matches = (baseNode.querySelectorAll([selector]) as List).cast<Element>();
    } else if (baseNode is Document) {
      matches = (baseNode.querySelectorAll([selector]) as List).cast<Element>();
    } else if (baseNode?.parentNode is Element) {
      matches = ((baseNode!.parentNode as Element).querySelectorAll([selector]) as List).cast<Element>();
    }
  } catch (_) {}

  final nodeIds = matches.map((el) => ctx.forDevtoolsNodeId(el)).toList(growable: false);
  sendToFrontend(id, JSONEncodableMap({'nodeIds': nodeIds}));
}