I know it's possible to show a popup when clicking on the extension icon (top right of the browser, to the right of the address bar): chrome.browserAction
Also here is how to create an Options page, that will often have an URL like:
chrome-extension://ofodsfyizzsaaahskdhfsdffffdsf/options.html
Question: how is it possible to make that a single click on the extension icon opens the options.html page in a new tab?
I know it's possible to show a popup when clicking on the extension icon (top right of the browser, to the right of the address bar): chrome.browserAction
Also here is how to create an Options page, that will often have an URL like:
chrome-extension://ofodsfyizzsaaahskdhfsdffffdsf/options.html
Question: how is it possible to make that a single click on the extension icon opens the options.html page in a new tab?
Share Improve this question asked Jun 11, 2018 at 11:40 BasjBasj 46.7k110 gold badges459 silver badges808 bronze badges 1-
1
chrome.browserAction.onClicked.addListener(()=>{chrome.tabs.create({url:'options.html'})});
. For this to work, browserAction must not have an associated popup. – Iván Nokonoko Commented Jun 11, 2018 at 11:43
2 Answers
Reset to default 8You can use something like this in your background script:
background.js
chrome.browserAction.setPopup({popup:''}); //disable browserAction's popup
chrome.browserAction.onClicked.addListener(()=>{
chrome.tabs.create({url:'options.html'});
});
manifest.json
...
"browser_action": {
"default_title": "Options"
},
"background": {
"scripts": ["background.js"],
"persistent": true
}
...
Update for Manifest v3:
in the manifest.json
, add an empty action prop to be able to access chrome.action
:
"action": {}
you can find more configurations in this document.
Important notice: after the change in manifest, you will have to restart the browser for the "Load unpacked" to take effect.
in the background / service worker file, add a listener of click on extension icon event:
chrome.action.onClicked.addListener(() => {
chrome.runtime.openOptionsPage(() => console.log("debug: options page opened"));
});