0

I am trying to create a chrome extension that will automatically click on button 4 times in every hour on a specified webpage when you click on extension, but for some reason it does nothing to find button and click.

  1. auto click on given extension directs to URL www.ighoot.com
  2. auto click login button
  3. auto click again second login waits or load 5sec
  4. auto click on autofollow button
  5. auto click on getfollow button
  6. repeat above steps in every 60min

How to access and autoclick the button by using its Xpath.

manifest.json

{
  "manifest_version": 2,

  "name": "AutoFollow",
  "description": "This allows the extension to auto click link and button in every hour",
  "version": "1.0",

"browser_action": {
    "default_icon": {"38": "auto.png"}
},

 "background": {
    "scripts": ["background.js"],

    "persistent": false
},
    "permissions": ["activeTab","tabs"]
}

background.js

 chrome.tabs.create

 chrome.browserAction.onClicked.addListener(function(tab) {
      var newURL = "http://ighoot.com";
        chrome.tabs.create({ url: newURL });
      chrome.tabs.executeScript({file: "content.js"});
});

content.js

if (interval) {
    clearInterval(interval);
    interval = 0;
} else {
    var btn = document.querySelector("#slogin");
    if (btn) {
        var interval = setInterval(function() {
            btn.click();
        }, 60 * 1000);
    }
}


function myFunc() {
    document.getElementById('hello').click();
};

setInterval(myFunc, 3000);
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
  • What *exactly* is shown in the [various appropriate consoles for your extension](https://stackoverflow.com/a/38920982/3773011) when you load and execute your extension? – Makyen Oct 14 '17 at 17:12

1 Answers1

0

The problem was this error:

Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "http://ighoot.com/". Extension manifest must request permission to access this host.

You can see this by opening your background script's console
(chrome://extensions -> Inspect views: background page)

And here is the fix: (manifest.json)
"permissions": [ "http://ighoot.com/" ]

Then, your code in content.js is broken but the line
document.querySelector("#slogin").click() on its own does work.

Jean-Alphonse
  • 800
  • 4
  • 10