检测已安装的Chrome扩展 [英] Detecting installed chrome extensions

查看:165
本文介绍了检测已安装的Chrome扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测Chrome扩展,但是我遇到了问题。当我尝试 jQuery.load()类似于
chrome-extension://jffbcpkfdlpegbadfomimojhgaaoaeed/icon.png 或其他文件,我得到这个错误:

 拒绝chrome扩展的加载://jffbcpkfdlpegbadfomimojhgaaoaeed/icon.png 。必须在web_accessible_resources清单键中列出资源,才能通过扩展名外的页面加载资源。 movie.php?id = 3079:1 
无法加载资源:net :: ERR_FAILED

我可以避免web_accessible_resources?我试图将文件名的大小写从icon.png改为ICON.png而没有成功( like this )。



这个想法只是为了检测扩展;没有别的。



我想做一些类似于 this 解决方案

扩展程序已安装,对于任何给定的扩展程序,您不应该依赖加载Web可访问的资源(对所有扩展不能均匀工作)的攻击,并使用 chrome.management API ,它专门用于此目的。

  chrome.management.get('keyoftheextensionyouwanttofind',function(info){
if(!info){console.log(Extension not installed) ;}
else if(!info.enabled){console.log(Extension installed,but disabled);}
else {console.log(Extension installed and active);}
});

是的,它会触发权限警告


I'm trying to detect chrome extensions, but I have a problem. When I try to jQuery.load() something like chrome-extension://jffbcpkfdlpegbadfomimojhgaaoaeed/icon.png or some other file, I get this error:

Denying load of chrome-extension://jffbcpkfdlpegbadfomimojhgaaoaeed/icon.png. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension. movie.php?id=3079:1
Failed to load resource: net::ERR_FAILED 

Can I avoid web_accessible_resources? I tried to change the capitalization of the filename from something like icon.png to ICON.png without success (like this).

The idea is ONLY to detect extension; nothing else.

I want to do something like this.

解决方案

If you need to detect that an extension is installed, for any given extension, you should not rely on hacks like loading web-accessible resources (which do not work uniformly for all extensions) and use chrome.management API which is specifically there for this purpose.

chrome.management.get('keyoftheextensionyouwanttofind', function(info){
  if (!info) { console.log("Extension not installed"); }
  else if (!info.enabled) { console.log("Extension installed, but disabled"); }
  else {console.log("Extension installed and active");}
});

Yes, it will trigger a permission warning.

这篇关于检测已安装的Chrome扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆