Skip to content
Advertisement

Node.js Lighthouse custom Gatherer/Audit – Protocol error (Runtime.evaluate): Object reference chain is too long

I am trying to implement custom audits using the lighthouse library lighthouse and executing some Javascript commands within the Gatherer I get the following error:

Protocol error (Runtime.evaluate): Object reference chain is too long

In detail I have the following Gatherer:

'use strict';
const { Gatherer } = require('lighthouse');

class customGatherer extends Gatherer {
 afterPass(options, loadData) {
    const expression = `window.document.getElementsByTagName('*')`;

    const driver = options.driver;

    return driver.evaluateAsync(expression);
 }
}

module.exports = customGatherer;

That with the expression defined above triggers the problem. There seems to be too much information and I can’t manage it. I’m testing the command on a web page and it returns 1059 collections (HTMLCollection(1059)).

When I run the lighthouse command to inspect a page, the warning is created and the result cannot be manipulated within the audit:

LH:Runner:warn customGatherer, required by audit my-custom-audit, encountered an error: Protocol error (Runtime.evaluate): Object reference chain is too long +0ms

NB: In the lighthouse log i can see also this error:

 LH:method <= browser ERR:error Runtime.evaluate  +24ms

I need to have a Gatherer that returns all HTMLCollection elements in order to compute them to get all the fonts on the page. How can I get around this problem?

Advertisement

Answer

There is already an artifact that collects all font information on a page: https://github.com/GoogleChrome/lighthouse/blob/master/types/artifacts.d.ts#L139

As for the actual error, you’d need to write a more complex function that you’d pass to evaluate to process the DOM and return only the data you want. If you write anything more than a single-line expression I suggest using driver.evaluate instead (see the Lighthouse repo for examples).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement