最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 8

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
}
...

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"));
});

发布评论

评论列表(0)

  1. 暂无评论