← Chrome 150 reference

v150 · html · dom · parser

Parse processing instructions in HTML

Chrome 150 extends the HTML parser to recognise and preserve XML-style processing instructions (<?target data?>) as ProcessingInstruction DOM nodes. Previously these were silently discarded by the HTML parser; now they appear in the DOM tree alongside elements and text nodes.

at a glance

Shipped inChrome 150 (Enabled by default)
StatusEnabled by default
API changeProcessingInstruction nodes now appear in the HTML DOM
Standards position (Firefox)No signal
Standards position (Safari)Support
ChromeStatus6534495085920256 — Parse processing instructions in HTML
Source: chromestatus.com/feature/6534495085920256

what processing instructions are

Processing instructions (PIs) are a construct from XML with the syntax <?target data?>. They exist in the DOM as ProcessingInstruction nodes (a subclass of CharacterData) with target and data properties. They are already first-class citizens in XML/XHTML DOM but have historically been stripped by the HTML5 parser.

Typical use cases include:

Source: chromestatus feature summary

shape of the API

InterfacePropertyDescription
ProcessingInstructiontargetThe PI target string (before the first space)
ProcessingInstructiondataThe PI data string (after the first space, up to ?>)
NodenodeType7 (Node.PROCESSING_INSTRUCTION_NODE)

Processing instructions are accessible through normal DOM traversal: TreeWalker, NodeIterator, childNodes, querySelector (does not match PIs, but iteration does).

Source: DOM Living Standard §ProcessingInstruction

example

<!-- HTML source with processing instructions -->
<div id="content">
  <?stream-start id="chunk-1"?>
  <p>First paragraph</p>
  <?stream-end id="chunk-1"?>
</div>

<script>
// Chrome 150+: PIs are now in the DOM
const walker = document.createTreeWalker(
  document.getElementById('content'),
  NodeFilter.SHOW_PROCESSING_INSTRUCTION
);
let node;
while ((node = walker.nextNode())) {
  console.log(node.target, node.data);
  // "stream-start" "id=\"chunk-1\""
  // "stream-end"   "id=\"chunk-1\""
}

// Access via childNodes
const div = document.getElementById('content');
for (const child of div.childNodes) {
  if (child.nodeType === Node.PROCESSING_INSTRUCTION_NODE) {
    console.log('PI:', child.target, child.data);
  }
}
</script>
Source: DOM Living Standard §ProcessingInstruction

browser support

BrowserSupportNotes
Chrome 150+Enabled by defaultAll platforms
FirefoxNo signal
SafariSupport
Source: chromestatus.com/feature/6534495085920256

see also