S
S
Stanislav2017-03-31 00:37:31
Mozilla Firefox
Stanislav, 2017-03-31 00:37:31

Firefox passing a message from a page to a plugin. "ReferenceError: browser is not defined"?

Wrote a website plugin. Everything works fine on chrome, but in Firefox it can't find the browser component.
I'm trying to get the message from the page from background.js like this:

function doSomethind(){
    //много кода также с использованием browser (ошибок нет, все работает)
}
browser.runtime.onMessageExternal.addListener(
  function(request, sender, sendResponse) {
    if (request.screenshot){
        doSomething();
        console.log ('success');
    }
});

From the side of the site, the handler hangs on the button:
$('#saveImage').click(function(){
    
    browser.runtime.sendMessage( 
        {screenshot: {
            'user_id': 123,
            'project_id': 123
        }},
        function(response) {});

});

On the side of the plugin, the browser is perceived normally and does its job. On the site, when the button is pressed, an error pops up:
ReferenceError: browser is not defined
Accordingly, in chrome, when using chrome instead of browser, everything works fine. These methods are all available in WebExtensions and are fully compatible with them. What is the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question