Cannot use chrome.management API

Now I want to run a chrome application from the chrome extension (in fact, I want to run a chrome application through a URL that I am not going to do). That is the question. I added

  "permissions": [
    "management"
  ],

in the extension manifest. However, when I want to run the application using

chrome.management.launchApp("XXXX", function() {});

the console says

Uncaught TypeError: cannot read property 'launchApp' from undefined

So I wonder why I cannot use the chrome control API. Thank!

+4
source share
1 answer

A workaround for this is available in the SO question. Launch the chrome application using the website button

Hasitha .

  • , -

                                                     //data passed from web to chrome app
    chrome.runtime.sendMessage('your_chrome_app_id', { message: "version" },
        function (reply) {
            if (reply) {
                if (reply.version) {
                    //log the response received from the chrome application
                    console.log(reply.version);
                }
            }
        }
     );
    
  • chrome manifest.json URL- externally_connectable :

    {          "name": " ",          "description": "App Desc",          "": "1",

          ...
    
          "externally_connectable": {
            "matches": ["*://localhost:*/"]
          }
        }
    
  • background.js , , - :

    chrome.runtime.onMessageExternal.addListener(
      function(request, sender, sendResponse) {
        if (request) {
          if (request.message) {
            if (request.message == "version") {
    
              //my chrome application initial load screen is login.html
              window.open('login.html');
    
              //if required can send a response back to the web site aswell. I have logged the reply on the web site
              sendResponse({version: '1.1.1'});
            }
          }
        }
        return true;
      });
    
+1

Source: https://habr.com/ru/post/1545808/


All Articles