Broccoli plugin for manipulating HTML with jsdom.

Usage no npm install needed!

<script type="module">
  import broccoliDomFilter from '';


Broccoli Dom Filter

Latest npm release TravisCI Build Status GitHub Actions CI

Broccoli plugin for manipulating HTML with jsdom.


Add an Element in app/index.html:

const BroccoliDomFilter = require('broccoli-dom-filter');

const filter = new BroccoliDomFilter('app', {
  files: ['index.html'],
  processors: [(jsdom => {
    const document = jsdom.window.document;
    const head = document.querySelector('head');
    const insertBefore = head.querySelector('title');
    const meta = document.createElement('meta');

    meta.setAttribute('name', 'test-name');
    meta.setAttribute('content', 'test-content');

    head.insertBefore(meta, insertBefore);

    return jsdom;


new BroccoliDomFilter(inputNodes, options)

BroccoliDomFilter is a subclass of BroccoliPersistentFilter which has additional options available in the constructor. Please see BroccoliPersistentFilter Options for documentation.

  • inputNodes: An array of node objects that this plugin will read from. Nodes are usually other plugin instances; they were formerly known as "trees".
  • options
    • files: The list of files to process the list of patterns against. This is an array of strings.
    • processors: An array of callbacks that will process jsdom and return jsdom.
    • processorOptions: A context that can will be passed as the second argument to a processor.

function processor(jsdom, processorOptions = {})

Processors allow you to modify the document currently being processed by jsdom. A processor MUST take the jsdom argument and MUST return the jsdom argument. If you created an instance of BroccoliDomFilter with processorOptions, that is provided to your processor as the second argument, otherwise it will default to {}.


npm install
npm test


This project is licensed under the MIT License.