2013-09-05 39 views
0

嗨我已经找到了其他类似的问题在stackoverflow但他们都没有解决的目的。如何在新标签页中打开我的Chrome扩展程序?

我希望我的Chrome扩展/应用程序可以像打开POSTMAN扩展一样在完整选项卡中打开。

我的manifest.json

{ 
"name": "Sample App", 
"manifest_version": 2, 
"version": "0.0.1", 
"app": { 
"background": { 
    "scripts": ["main.js"] 
    } 
}, 
"icons": { "128": "icon.png" }, 
"permissions" : ["tabs" ] 
    } 

我main.js(别名background.js)

chrome.app.runtime.onLaunched.addListener(function() { 
chrome.tabs.create({'url': chrome.extension.getURL('index.html')}, function(tab) { 
alert("Hi"); 
}); 

}); 

index.html的是我想在打开新标签加载该文件。

回答

2

我第一次响应这里计算器,请温柔...

我发现它更容易添加“启动”:{“LOCAL_PATH”:“index.html的”}对于manifest.json内文件。请参阅下面的示例清单文件。

{ 
"manifest_version" : 2, 
"name": "Hello World!", 
"description": "My first Chrome App.", 
"version": "0.1", 
"app": { 
    "launch" : { 
    "local_path" : "index.html" 
    } 
}, 
"icons": { "16": "icon.png" } 
} 

请记住,这个例子是非常基本的,它已被剥夺了一些不必要的信息,如背景脚本,但它应该完成你想要的。

http://developer.chrome.com/apps/first_app.html

0

chrome.app.runtime.onLaunched仅适用于Chrome应用程序,不适用于扩展程序。您的后台页面代码会在Chrome浏览器启动时自动运行,因此您可以直接使用chrome.tabs.create(...)开始。

此外,您需要包含index.html以及您的扩展中包含的任何资源,该页面将用于清单中的web_accesible_resources部分。

相关问题