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>
There are some problems in your script
Manifest registration
You should register background as
or
CSP
If you are looking to have background as a
htmlpage eliminate<script>tag in html page to adhere Content Security Policy.After Eliminating these problems i got your script running.
Working Version
manifest.json
Registered background page to manifest file.
background.js
Used your code without any modifications.
I was able to create window as expected.
References