I have a background script where I send a message after I pressed hotkey but the content script does not intercept it. Why? I added breakpoint to the line with if (package.command) … and some other lines and nothing paused. The message is send successfully.
background script:
// Get current tab id
chrome.tabs.query(
{
active: true,
currentWindow: true // send message to the active window
},
function(tabs) {
chrome.tabs.sendMessage( tabs[0].id, package )
}
content script:
chrome.runtime.onMessage.addListener(
function(package){
if (package.command) ...
}
)
This is because yesterday or maybe today’s morning it worked. I mean I could inject css styles to web-page when I pressed the hotkey. No I cannot.
In general I’d suggest that you try to get your extension to run in Chrome first, and then “port” it to Firefox. Chromes Dev-Tools support for WebExtensions is simply better.
In chrome you can:
Check whether your content script is actually running in the tab you want it to.
Set a break point in both the line with sendMessage in the background script to check the tabId, and in the first line of the message listener of the contnent script to see exactly what happens.
You can do the same in Firefox too, but in my experience it’s much easier in Chrome, especially when you reload the extension frequently.
I found the problem. I am trying to run the hotkey/command on file:/// not http://
so it seems it is impossible to inject the C.S. to file:/// html document.
I use this pattern:
“content_scripts”: [
{
“matches”: [":///*"],
I have different Chrome. I have different icon for Menu, This is 3 horizontal lines. I see the hotkey for devtools is the same as in Firefox. And I had to click on The mode for developers checkbox, which is not visible on your screenshot because you expanded the menu.
Edit:
The chrome cries:
Too many shortcuts specified for ‘commands’: The maximum is 4.
Ugh…
Why they have 4 commands limit? I planned to use about 5 or 6 tools.
I share your concern. I think to counter this, the Firefox devs need to:
Fix all the little bugs (or undocumented ‘features’) that make developing an extension for Firefox considerably more annoying than necessary.
Improve the performance of Firefox in general and of WebExtensions. Which mostly means to press on with e10s. This is literally the only way that I see any future for Firefox at all. I have developed an extension that works very fast in chrome (page load times so low that you wouldn’t believe that the page was loaded and not just shown. In Firefox the same thing is so slow that it is almost unusable.
Make the things that make Firefox great available to modern extensions. WebExtensions as they are now won’t be sufficient. If I have the choice between a fast browser with WebExtensions and a slow browser with WebExtensions, why would I choose Firefox? If I dislike Google I can still use Opera, or, now that that is being sold to Chinese, Vivaldi.
We will see if Mozilla is able to do so while Firefox still has some users …
It seems like they are not aware about that bugs, even that I have posted at least 10 bugs during last weeks. One of the project co-workers asked me to send the addon I use, but I cannot help when the addon is not finished.
You can go to the bug reports and see their status there. Since you filed them, you should be getting updates on their progress or resolution. Some bugs can take a long time to be resolved, unfortunately.