I am trying to create my first Chrome extension, but I have problems to make JS work properly. All I want to do when I click "Activer" is a popup that says hello.
This is the code I found on github that I was trying to adapt to my code. When I check the extension, I get an error message:
Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "http://stackoverflow.com/questions/ask". Extension manifest must request permission to access this host.
at HTMLDivElement.hello (chrome-extension:
Here is my manifest.json
{
"name": "e-kootsa",
"version": "1.0",
"manifest_version": 2,
"description": "Ce plugin vous permet d'écouter le texte d'une page",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"options_page": "options.html"
}
Here is my popup.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style type="text/css">
body{
margin: 0px;
padding: 0px;
font-family: Arial, Sans-serif;
font-size: 20px;
width: 200px;
}
.selection{
text-align: center;
margin-bottom: 5px;
}
.global{
padding-top: 5px;
}
a{
text-decoration: none;
color: #000;
}
</style>
</head>
<body>
<div class="global">
<div class="selection"><a href="options.html" target="_blank">Paramètres</a></div>
<hr />
<div class="selection" id="clickme"><a href="#">Activer</a></div>
<hr />
<div class="selection"><a href="about.html" target="_blank">À propos</a> </div>
</div>
<script type="text/javascript" src="popup.js"></script>
</body>
</html>
Here is a list of popup.js
function hello() {
chrome.tabs.executeScript({
file: 'alert.js'
});
}
document.getElementById('clickme').addEventListener('click', hello);
And here is my alert.js
alert('hello ' + document.location.href);
console.log('Tryhard');
I know that I must have made some mistakes, but it's still hard for me to figure out how to make everything work ...
Thank you in advance!
source
share