Answer the question
In order to leave comments, you need to log in
How to correctly handle the launch of a google chrome extension?
I'm trying to write extensions for google chrome, re-read the official documentation and guides in Russian, I can't find what the problem is.
There is a background.js file
// Вызывается, когда пользователь нажимает на действие браузера.
chrome.browserAction.onClicked.addListener(function(tab) {
// Отправить сообщение на активную вкладку
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "clicked_browser_action"});
});
});
chrome.runtime.onMessage.addListener(
function(message, callback) {
if (message == "licked_browser_action"){
chrome.tabs.executeScript(alert('hello'));
}
return true
});
{
"manifest_version": 2,
"name": "test",
"version": "1.0.0",
"content_security_policy": "script-src 'self'; object-src 'self'",
"background": {
"scripts": ["background.js"]
},
"permissions": [
"activeTab"
],
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["search_in_file.js", "test.js"]
}
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"web_accessible_resources": [
"search_in_file.js", "test.js"
]
}
Answer the question
In order to leave comments, you need to log in
To begin
"licked_browser_action"
with, it does not coincide with "clicked_browser_action"
Well, check it step by step. The first thing is that the handler generally fires with every click, that is, we need to find out whether the click handler itself or something after it misfires. To do this, insert something like this:
Well, and so on down the chain. According to the logs, it will be further visible where the plug is.
console.log("onClicked");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question