extension works correctly, but when i try execute in url "chrome://" (exampe: chrome://extensions/) extension do not work correctly. And after extension do not work correctly in any url. After reload extension and page again extension works correctly. I think when i try extension in url "chrome://" (exampe: chrome://extensions/) browser block my background.js. After reloads extension and page browser allow background.js, It may be for permission section in manifest.json
manifest.json
{
"manifest_version": 2,
"name": "X Plugin",
"description": "Post selected text for translate",
"version": "0.1",
"background": {
"scripts": ["background.js"],
"persistent": true
},
"icons": {
"64": "icon_64x64.png"
},
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"http://*/",
"https://*/"
]
}
popup.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="popup.js"></script>
</head>
<body>
<form id="addbookmark" method="POST" action="http://www.somesite.az" target="_blank">
<img src="logo.png" />
<p><label for="direction">Direction</label><br />
<select name="lang_left" id="id_lang_left" class="dlc_select"></select>
<select name="lang_right" id="id_lang_right" class="dlc_select"></select>
<p><label for="text">Text</label><br />
<textarea name="from" id="id_from" rows="6" cols="35"></textarea>
</p>
<p>
<input id="translate" type="submit" name="translate" value="Translate" />
<span id="status-display"></span>
</p>
</form>
</body>
</html>
popup.js
// This callback function is called when the content script has been
// injected and returned its results
function onPageInfo(o) {
document.getElementById('id_from').innerText = o.summary;
}
window.addEventListener('load', function(evt) {
chrome.extension.getBackgroundPage().getPageInfo(onPageInfo);
});
background.js
// Array to hold callback functions
var callbacks = [];
// This function is called onload in the popup code
function getPageInfo(callback) {
// Add the callback to the queue
callbacks.push(callback);
// Inject the content script into the current page
chrome.tabs.executeScript(null, { file: 'content_script.js' });
};
// Perform the callback when a request is received from the content script
chrome.extension.onMessage.addListener(function(request) {
// Get the first callback in the callbacks array
// and remove it from the array
var callback = callbacks.shift();
// Call the callback function
callback(request);
});
content_script.js
// This script is only injected when the popup form is loaded
// (see popup.js), so we don't need to worry about waiting for page load
// Object to hold information about the current page
var pageInfo = {
'title': document.title,
'url': window.location.href,
'summary': window.getSelection().toString()
};
// Send the information back to the extension
chrome.extension.sendMessage(pageInfo);