Cannot find .visible property of traces in dcc.Graph component


I’m quite new to Plotly.js (and JS in general), but I am working on a custom Dash component, in which I need to know the visible status of the traces in an existing dcc.Graph component. More specifically, I need to separate the visible traces from the invisible ones into two different lists.

I have tried following the tips given by Get state of current chart - #5 by Isisgv this discussion, but I have just seen in my project that the .data property of the graph does not contain the .visible property mentioned in the discussion.
So, I have come here to search for more help. Here’s my code:

let graphDiv = document?.querySelectorAll('div[id*="' + gdID + '"][class*="dash-graph"]');
if (graphDiv.length > 1) {
    throw new SyntaxError('multiple graphs with ID="' + gdID + '" found; n=' + graphDiv.length + ' \n(either multiple graphs with same ID\'s or current ID is a str-subset of other graph IDs)');
} else if (graphDiv.length < 1) {
        throw new SyntaxError('no graphs with ID="' + gdID + '" found');

graphDiv = graphDiv?.[0]?.getElementsByClassName('js-plotly-plot')?.[0];
if (!isElement(graphDiv)) {
    throw new Error(`Invalid gdID '${gdID}'`);

console.log(`trace.visible? : ${[0].visible}`);