Chrome浏览器扩展程序chrome.app.isInstalled总是返回false? [英] chrome.app.isInstalled always returns false for Google Chrome extensions?
问题描述
为什么chrome.app.isInstalled总是会为Google Chrome扩展程序返回false?
动态地在页面加载时添加一个链接元素:
<< ; link type =text / css =chrome-webstore-itemhref =https://chrome.google.com/webstore/detail/itemID>
以下是点击按钮时执行的一些Javascript代码:
if(!chrome.app.isInstalled){
alert('extension is about to be installed!');
install_extension();
} else {
alert('extension is installed already。');
}
第一次点击按钮时,Google Chrome问我是否想要安装扩展。我同意并且扩展已正确安装。当我刷新页面时,我再次点击该按钮,Google CHrome要求我再次安装扩展程序,即使在2分钟前安装了该扩展程序。换句话说,即使安装了扩展程序,chrome.app.isInstalled也总是返回false。为什么?
请参阅 chrome.app.isInstalled始终返回为false:
chrome.app.isInstalled
适用于托管应用程序 strong>(它定义了一组包含应用程序的URL)。扩展可以反而表明它们已经通过在页面中注入DOM节点来安装(参见 https://developers.google.com/chrome/web-store/docs/inline_installation#already-installed )。
该链接描述了测试您的扩展是否已安装的策略: 有一个内容脚本注入一个DOM节点到每个页面。这个节点应该有一个非常具体的ID,例如< div id ='my-extension-installed-with-id-sdgdthsdfgdtyjufwknsdkos'>
如果该节点存在,则内容脚本正在运行;因此,扩展已安装。如果它不存在,则假定没有安装该扩展。
app.isInstalled
。相反,您会检查DOM节点的存在以证明扩展的存在。 why does chrome.app.isInstalled always return false for Google Chrome extensions?
Dynamically I add a link element on page load:
<link type="text/css" rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/itemID">
The following is some Javascript that executes when a button has been clicked:
if (!chrome.app.isInstalled) {
alert('extension is about to be installed!');
install_extension();
}else{
alert('extension is installed already.');
}
The first time I clicked the button, Google Chrome asked me if I wanted to install the extension. I agree and the extension was installed correctly. When I refreshed the page, I clicked the button once again and Google CHrome asked me to install the extension once again even when I had installed it 2 minutes ago. In other words, chrome.app.isInstalled always return false even when the extension is installed. Why?
See chrome.app.isInstalled Always Returns as "false":
chrome.app.isInstalled
is meant for use by hosted apps (which define a set of URLs that encompass the app). Extensions can instead indicate that they're installed already by injecting a DOM node into the page (see second half of https://developers.google.com/chrome/web-store/docs/inline_installation#already-installed).
That link describes a strategy for testing if your extension is installed:
Have a content script inject a DOM node into every page. This node should have a very specific ID, e.g.,
<div id='my-extension-installed-with-id-sdgdthsdfgdtyjufwknsdkos'>
On button press, have your page test if that node exists.
If the node exists, the content script is running; therefore, the extension is installed. If it does not exist, assume the extension is not installed.
Injecting a DOM node won't affect the state of app.isInstalled
. Instead, you check for the existence of the DOM node as proof of the extensions presence.
这篇关于Chrome浏览器扩展程序chrome.app.isInstalled总是返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!