【问题标题】:Building a Chrome extension for the Chrome Web Store, want to open in a new tab为 Chrome 网上应用店构建 Chrome 扩展程序,希望在新选项卡中打开
【发布时间】:2016-08-25 00:21:35
【问题描述】:

为 Chrome 网上应用店构建 Chrome 扩展程序,想在新标签页中打开,无法解决。这是my extension,如您所见,它正在扩展中打开窗口。我希望它能够打开一个新标签并直接进入网页,或者从他们所在的任何页面加载我的网站。

我写的 JSON:

    {
"name": "Our Blinds",
"version": "0.2",
"manifest_version": 2,
"description": "This app will link to the Our Blinds website, where you can buy made to measure window blinds",
"browser_action": {
    "default_icon": "128.png",
    "default_title": "made to measure window blinds",
    "default_popup": "www.ourblinds.co.uk"
},
"content_security_policy": "script-src 'self' https://www.google.com; object-src 'self'",
"icons": {
    "128": "icon.png"
}
}        

我需要更改哪些内容才能在新标签页中打开它?我认为通过将网址作为默认弹出窗口,它应该在新的或相同的选项卡中打开。

例如,this extension 执行我希望我的扩展程序执行的操作,但显然是针对我自己的网站而不是他们的网站。我希望人们能够添加扩展程序,并在 1 次单击后出现在我的网站 www.ourblinds.co.uk 上。

【问题讨论】:

  • 我已将其更改为 { "name":"Our Blinds", "version":"1.3", "manifest_version":2, "description":"此扩展程序将链接到 Our Blinds百叶窗网站,您可以在其中购买定制的百叶窗”,“browser_action”:{“default_icon”:“128.png”,“default_title”:“定制的百叶窗”,“default_popup”:“www.ourblinds。 co.uk/", "permissions":"new tab" }, "content_security_policy":"script-src 'self' google.com; object-src 'self'" } 仍然无法正常工作,现在无法加载网站。
  • 我已将其删除,因为它不起作用。让它作为应用程序工作...chrome.google.com/webstore/detail/our-blinds/… 想要一个扩展程序与应用程序完全相同,请帮助。

标签: json google-chrome google-chrome-extension chrome-web-store


【解决方案1】:

"default_popup" 清单中的键只能指向包含弹出窗口的本地 html 文件(单击工具栏图标后出现的一个非常小的窗口)。你不需要它。使用带有click listenerbackground (event) page 脚本,而不是opens a new tab

  • manifest.json,相关部分:

        "browser_action": {
            "default_icon": "128.png",
            "default_title": "made to measure window blinds",
        },
        "background": {
            "scripts": ["background.js"],
            "persistent": false
        },
    
  • background.js:

    chrome.browserAction.onClicked.addListener(function(tab) {
        chrome.tabs.create({
            url: 'http://exampe.com',
            active: true,
        });
    });
    

附:您的 128px 图标现在看起来不清晰,因为它会自动拉伸到正确的大小。考虑制作 Chrome 使用的 16x16、19x19、32x32、38x38 尺寸的适当缩放图标,并以相同的方式声明它们("16": "16.png" 等)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 2011-01-25
    相关资源
    最近更新 更多