onRequestChildNodes method

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

Implementation

void onRequestChildNodes(int? id, Map<String, dynamic> params) {
  // https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-requestChildNodes
  if (DebugFlags.enableDevToolsLogs) {
    devToolsLogger.finer('[DevTools] DOM.requestChildNodes nodeId=${params['nodeId']} depth=${params['depth']}');
  }
  final ctx = dbgContext;
  if (ctx == null) {
    sendToFrontend(id, null);
    return;
  }
  final int? frontendNodeId = params['nodeId'];
  if (frontendNodeId == null) {
    sendToFrontend(id, null);
    return;
  }

  final targetId = ctx.getTargetIdByNodeId(frontendNodeId);
  if (targetId == null) {
    sendToFrontend(id, null);
    return;
  }
  final Node? parent = ctx.getBindingObject(Pointer.fromAddress(targetId)) as Node?;
  if (parent == null) {
    sendToFrontend(id, null);
    return;
  }

  // Build immediate children list (filter whitespace-only text nodes)
  final children = <Map>[];
  for (final child in parent.childNodes) {
    if (child is Element || (child is TextNode && child.data.trim().isNotEmpty)) {
      children.add(InspectorNode(child).toJson());
    }
  }

  if (devtoolsService is ChromeDevToolsService) {
    final pId = ctx.forDevtoolsNodeId(parent);
    ChromeDevToolsService.unifiedService
        .sendEventToFrontend(DOMSetChildNodesEvent(parentId: pId, nodes: children));
    if (DebugFlags.enableDevToolsProtocolLogs) {
      devToolsProtocolLogger
          .finer('[DevTools] -> DOM.setChildNodes parent=$pId count=${children.length}');
    }
  }
  // Respond to the method call with empty result
  sendToFrontend(id, JSONEncodableMap({}));
}