How to open chrome-extension in new tab by default? Not in the new pop-up as like the present time.
I have the:
//manifest.json
{
...
"background": {
"scripts": ["js/background.js"],
"persistent": false
},
"browser_action": {
"default_title": "Test Viewer v.1.0",
"default_icon": "icon.png",
"default_popup": "index.html"
},
"permissions": [
"unlimitedStorage",
"notifications",
"activeTab",
"tabs",
"https://docs.google.com/*",
"downloads"
]
...
}
and
//background.js
chrome.browserAction.onClicked.addListener(function(tab){
chrome.tabs.create({
url: ("index.html"),
type: "normal"
});
});
In the docs https://developer.chrome.com/extensions/windows this type is specified as type: "normal"
which open the "normal browser window" as I wish, but it doesn't work. Where is error?
Get rid of default_popup
. The presence of this attribute declaratively means you want to open your extension's popup when clicked.
As long as the browser_action
section is present at all, you can use the chrome.browserAction.onClicked
event to run your handler.
1) I have deleted default_popup
property in manifest.json
by advice @Josh Lee and 2) use this code in background.js
:
chrome.browserAction.onClicked.addListener(function(tab){
chrome.tabs.create({
'url': chrome.runtime.getURL("index.html#window")
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.