I am trying to create a chrome extension that will click on an element on a webpage when you click a button on the extension, but for some reason it does nothing no matter what I try.
I've got this so far
manifest.json
{
manifest_version: 2,
name: Such Activity,
description: Wow,
version: 1.0,
permissions: [
tabs, <all_urls>
],
browser_action: {
default_icon: icon.png,
default_popup: popup.html
},
content_scripts: [
{
matches: [ <all_urls> ],
js: [content_script.js]
}
]
}
popup.html
<!doctype html>
<html>
<head>
<title>activity</title>
<style>
</style>
<script src=content_script.js></script>
</head>
<body>
<button id=clickactivity>click</button>
</body>
</html>
content_script.js
function ClickPlanet()
{
var planets = document.getElementsByClassName(planet-name);
var randomplanet = Math.floor(Math.random() * planets.length);
var clickplanet = planets[randomplanet];
clickplanet.click();
setInterval(function () { ClickPlanet() }, 2000);
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('clickactivity').addEventListener('click', ClickPlanet);
});
All I seem to be getting is this error
Uncaught TypeError: Cannot read property 'click' of undefined
I've been fiddling around with this for hours, but I can't get it to work. Any and all help is appreciated!