Olá. Eu estou fazendo uma extensão simples para o Google Chrome. Eu gostaria que o menu de contexto dela abrisse um link em uma nova aba, porém não está funcionando.
manifest.json
{
"name": "Chroweet",
"manifest_version": 2,
"version": "1.0",
"description": "Tweet on Chrome only with a simple click",
"background": {
"scripts": ["background.js"]
},
"background": {
"page": "background.html"
},
"browser_action": {
"default_icon": "img/twitter-logo-19.png",
"default_popup": "background.html"
},
"icons": {
"19" : "img/twitter-logo-19.png",
"48" : "img/twitter-logo-48.png",
"128" : "img/twitter-logo-128.png"
},
"permissions": [
"tabs",
"activeTab"
],
"permissions": ["contextMenus"],
"background": {
"persistent": false,
"scripts": [
"background.js"
]
}
}
background.js
chrome.runtime.onInstalled.addListener(function() {
chrome.contextMenus.create({
title: 'Tweeet it',
id: 'menu1',
contexts: ['selection'],
});
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId === "menu1") {
var search = document.getElementById('ttweet');
var searchButton = document.getElementById('buttonTweet');
chrome.browserAction.onClicked.addListener(function(activeTab){
var newURL = "https://twitter.com/intent/tweet?text="+search.value;
window.open("https://twitter.com/intent/tweet?text="+search.value);
});
}
});
background.html
<!DOCTYPE html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Ubuntu:bold' rel='stylesheet' type='text/css' />
<link href='style.css' rel='stylesheet' type='text/css' />
<script src="twitter.js" type='text/javascript'></script>
</head>
<body>
<div>
<header>
<h1><img src="img/twitter-logo-large.png" width="100px"/></h1>
</header>
<section>
<input id="#ttweet"/>
<button id="buttonTweet">Tweet</button>
</section>
</div>
</body>
</html>
Alguém sabe por que isso acontece?