Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open the extension's options.html page in new tab when clicking on extension icon

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

enter image description here

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?

like image 433
Basj Avatar asked Jan 28 '23 23:01

Basj


1 Answers

You 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
}
...
like image 141
Iván Nokonoko Avatar answered Feb 08 '23 23:02

Iván Nokonoko