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

javascript - How to open chrome-extension in new tab by default - Stack Overflow

programmeradmin0浏览0评论

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",
            "/*",
            "downloads"
        ]
    ...
    }

and

//background.js
chrome.browserAction.onClicked.addListener(function(tab){
     chrome.tabs.create({
        url: ("index.html"),
        type: "normal"
    });
});

In the docs this type is specified as type: "normal" which open the "normal browser window" as I wish, but it doesn't work. Where is error?

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./*",
            "downloads"
        ]
    ...
    }

and

//background.js
chrome.browserAction.onClicked.addListener(function(tab){
     chrome.tabs.create({
        url: ("index.html"),
        type: "normal"
    });
});

In the docs https://developer.chrome./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?

Share asked May 7, 2018 at 19:23 PrinceOFFPrinceOFF 953 silver badges14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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

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.

发布评论

评论列表(0)

  1. 暂无评论