Is it possible to show custom content in Tab
Is it possible to insert content NOT loaded from a url, into a tab after creating a new tab by using;
chrome.tabs.create(object createProperties, function callback)
Can this be done, or is there any other way to achieve t开发者_运维百科he required effect?
Well, sort of. Each tab in Chrome must have some url, even a blank page. You can create a tab linked to html page from your extension folder though, that's what would be a workaround.
So if you create a stub html page called "newTab.html" and put it into extension folder:
<html>
<head>
<script>
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
//build a page from received data
if(request.param1 == "value1") {
//...
}
});
</script>
</head>
<body></body>
</html>
Then you can create a new tab linked to this page and send required data through messaging.
In background.html page:
chrome.tabs.create({url: "newTab.html"}, function(tab){
chrome.tabs.sendRequest(tab.id, {param1:"value1", param2:"value2"});
});
精彩评论