1

I am creating an extension that tracks the specific url and displays the date when that url is accessed then saves it into a text file. It works when I just run the page and script but when adding it to chrome it does nothing.

Manifest.json

{
    "name": "Login Tracker",
    "version": "0.1",
    "manifest_version": 2,
    "description": "A Chrome Extension that records the time that you log in",
    "browser_action": {
        "default_icon": "icon.png",
        "default_title": "Login Tracker"
    },
    "permissions": ["tabs",
        "background", "browsingData", "contextMenus", "downloads"
    ],
    "background": {
        "scripts": ["loginPage.js", "func.js"]
    }
}

loginPage.html

<html>
<head>
    <script type="text/javascript" src="func.js">
    </script>
</head>
<body>
    <h1>Login Tracker</h1>
    <p id=demo></p>
    <button type="button" onclick="myFunction()">Login</button>
</body>
</html>

func.js

function myFunction() {
    var d = new Date();
    document.getElementById("demo").innerHTML = d;
    var textToSave = d;
    var hiddenElement = document.createElement('a');
    hiddenElement.href = 'data:attachment/text,' +
        encodeURI(textToSave);
    hiddenElement.target = '_blank';
    hiddenElement.download = d;
    hiddenElement.click();
}

loginPage.js

chrome.browserAction.onClicked.addListener(function (activeTab) {
    var newURL = "loginPage.html";
    chrome.tabs.create({
        url: newURL
    });
});

Any idea why it does not do anything even just displaying the date? Its working when I view it in local but it does not do anything when being added to chrome. Any help will be appreciated.

scebotari66
  • 3,395
  • 2
  • 27
  • 34
Lance
  • 11
  • 2
  • 1
    Embedded js code like the onclick event doesn't work in extension pages. Move it to your js script. – wOxxOm Jun 04 '17 at 08:37
  • @wOxxOm how would that be? I do apologize as I am currently new to javascript and I am not able to find any similar thing for this. – Lance Jun 05 '17 at 08:19

0 Answers0