Angularjs 角度-如何检查是否安装了chrome extension

Angularjs 角度-如何检查是否安装了chrome extension,angularjs,google-chrome,google-chrome-extension,Angularjs,Google Chrome,Google Chrome Extension,我需要一个外部Angular脚本来检测用户是否安装了我的扩展 例如:一个用户安装了我的插件,然后转到一个有我脚本的网站。网站检测到我的扩展已安装,并相应地更新页面 我的代码: $.detectChromeExtension('[[id_chrome_extension]]', 'images/logo.png', myCallbackFunction); $.detectChromeExtension = function(extensionId, accesibleResource, cal

我需要一个外部Angular脚本来检测用户是否安装了我的扩展

例如:一个用户安装了我的插件,然后转到一个有我脚本的网站。网站检测到我的扩展已安装,并相应地更新页面

我的代码:

$.detectChromeExtension('[[id_chrome_extension]]', 'images/logo.png', myCallbackFunction);

$.detectChromeExtension = function(extensionId, accesibleResource, callback) {
    if (typeof(chrome) !== 'undefined'){
        var testUrl = 'chrome-extension://' +extensionId +'/' +accesibleResource;
        console.log(testUrl);
        $.ajax({
            url: testUrl,
            timeout: 1000,
            type: 'HEAD',
            success: function(){
                if (typeof(callback) === 'function') {
                    callback.call(this, true);
                }
            },
            error: function() {                
                if (typeof(callback) === 'function') {
                    callback.call(this, false);
                }
            }
        });
    }
    else {
        if (typeof(callback) === 'function') {
            callback.call(this, false);
        }
    }
};
我收到以下错误:

HEAD chrome extension://[[id\u chrome\u extension]]/images/logo.png net::ERR\u FAILED jquery.js:86235
未捕获错误:Chrome网络商店安装已挂起。

如何解决这个问题?

试试api,它也适用于应用程序

将此添加到您的清单中:

"externally_connectable": {
  "matches": ["*://*.example.com/*"]
}
然后从以下页面向您的分机发送消息:

// The ID of the extension we want to talk to.
var editorExtensionId = "abcdefghijklmnoabcdefhijklmnoabc";

// Make a simple request:
chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditor: url},
  function(response) {
    if (!response.success)
      handleError(url);
  });
并在分机中侦听消息:

    chrome.runtime.onMessageExternal.addListener(
  function(request, sender, sendResponse) {
    if (sender.url == blacklistedWebsite)
      return;  // don't allow this web page access
    if (request.openUrlInEditor)
      openUrl(request.openUrlInEditor);
  });

试试api,它也适用于应用程序

将此添加到您的清单中:

"externally_connectable": {
  "matches": ["*://*.example.com/*"]
}
然后从以下页面向您的分机发送消息:

// The ID of the extension we want to talk to.
var editorExtensionId = "abcdefghijklmnoabcdefhijklmnoabc";

// Make a simple request:
chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditor: url},
  function(response) {
    if (!response.success)
      handleError(url);
  });
并在分机中侦听消息:

    chrome.runtime.onMessageExternal.addListener(
  function(request, sender, sendResponse) {
    if (sender.url == blacklistedWebsite)
      return;  // don't allow this web page access
    if (request.openUrlInEditor)
      openUrl(request.openUrlInEditor);
  });

试试api,它也适用于应用程序

将此添加到您的清单中:

"externally_connectable": {
  "matches": ["*://*.example.com/*"]
}
然后从以下页面向您的分机发送消息:

// The ID of the extension we want to talk to.
var editorExtensionId = "abcdefghijklmnoabcdefhijklmnoabc";

// Make a simple request:
chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditor: url},
  function(response) {
    if (!response.success)
      handleError(url);
  });
并在分机中侦听消息:

    chrome.runtime.onMessageExternal.addListener(
  function(request, sender, sendResponse) {
    if (sender.url == blacklistedWebsite)
      return;  // don't allow this web page access
    if (request.openUrlInEditor)
      openUrl(request.openUrlInEditor);
  });

试试api,它也适用于应用程序

将此添加到您的清单中:

"externally_connectable": {
  "matches": ["*://*.example.com/*"]
}
然后从以下页面向您的分机发送消息:

// The ID of the extension we want to talk to.
var editorExtensionId = "abcdefghijklmnoabcdefhijklmnoabc";

// Make a simple request:
chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditor: url},
  function(response) {
    if (!response.success)
      handleError(url);
  });
并在分机中侦听消息:

    chrome.runtime.onMessageExternal.addListener(
  function(request, sender, sendResponse) {
    if (sender.url == blacklistedWebsite)
      return;  // don't allow this web page access
    if (request.openUrlInEditor)
      openUrl(request.openUrlInEditor);
  });


为了确保,
[[id\u chrome\u extension]]
是代码中实际id的占位符?为了确保,
[[id\u chrome\u extension]]
是代码中实际id的占位符?为了确保,
[[id\u chrome\u extension]
是代码中实际id的占位符?为了确保,
[[id\u chrome\u extension]]
是代码中实际id的占位符吗?