Reputation: 33
I'm trying to create a really simple chrome extension to open a hard-coded link in a new tab when clicked, and I'm not having any luck. After adding the extension the icon shows up, but nothing happens when I click on it. Any suggestions?
manifest.json
{
"name": "Drive Button",
"version": "1.0",
"manifest_version": 2,
"description": "Open Google Drive",
"browser_action": {
"default_icon": "icon.png"
},
"background": "background.html",
"permissions": [
"tabs"
]
}
background.html
<html>
<head>
<script>
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({url: "http://drive.google.com"});
});
</script>
</head>
</html>
Upvotes: 3
Views: 4914
Reputation: 18564
There are some problems in your script
You should register background as
"background": {
"scripts": ["background.js"]
},
or
"background": {
"page": "background.html"
},
If you are looking to have background as a html
page eliminate <script>
tag in html page to adhere Content Security Policy.
After Eliminating these problems i got your script running.
manifest.json
Registered background page to manifest file.
{
"name": "Drive Button",
"version": "1.0",
"manifest_version": 2,
"description": "Open Google Drive",
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"tabs"
]
}
background.js
Used your code without any modifications.
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.tabs.create({
url: "http://drive.google.com"
});
});
I was able to create window as expected.
Upvotes: 10