Reputation: 1
I want to create a browser extension, that simply opens the extensions background page, when I press on the extension's icon in the toolbar. The problem is, that when I add the browserAction listener to the toolbar icon in a script on the background page, it gets triggered again when I open the background page, so when I click the icon again, it opens 2 new tabs and so on...
file tree: click to view image
manifest.json
"manifest_version": 2,
"name": "Easy Films",
"version": "1.0",
"permissions": [
"tabs"
],
"browser_action": {
"default_title": "Easy Films",
"default_icon": "icons/browser_action.png"
},
"background": {
"page": "background/index.html"
}
}
background/index.html
<html>
<head>
</head>
<body>
<h1>Content will be added</h1>
<script src="script.js"></script>
</body>
</html>
background/script.js
function onStartup() {
browser.browserAction.onClicked.addListener(onClicked);
}
function onClicked() {
browser.tabs.create({
url: location.href
});
}
browser.runtime.onStartup.addListener(onStartup);
Upvotes: 0
Views: 125
Reputation: 56
Have you tried using start_url or scope?
"manifest_version": 2,
"name": "Easy Films",
"version": "1.0",
"start_url": "/",
"scope": "/",
Upvotes: -1