Currently, I am developing a userscript for a website and have run into an issue that states
Uncaught TypeError: is not a function
specifically in Chrome. Strangely, this error does not appear in Firefox. Despite spending the last hour trying to debug the script, I have yet to find a solution.
To help diagnose the problem within Chrome, I have included relevant code snippets below. The purpose of the script is to locate a button labeled 'Download' and retrieve the associated href link.
function getSubmissionSource(){
var controlBar = document.getElementsByClassName("button submission rounded");
for (var button of controlBar) { //errors here
var link = button.getElementsByTagName("a")[0];
if (link !== undefined && link.textContent == "Download") {
return link.href;
}
}
}
console.log(getSubmissionSource());
<div id="test"">
<span class="button submission rounded">
<a href="/view/18251152/" class="prev dotted">Older</a>
</span>
<span class="button submission rounded">
<a href="">-Remove from Favorites</a>
</span>
<span class="button submission rounded">
<a href="">Download</a>
</span>
<span class="button submission rounded">
<a href="">Note user</a></span>
<span class="button submission rounded">
<a href="/view/18385008/">Newer</a>
</span>
</div>