如何刷新/重新加载Chrome扩展程序? [英] How do I refresh/reload a Chrome Extension?

查看:867
本文介绍了如何刷新/重新加载Chrome扩展程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Chrome 4中的扩展程序(当前为4.0.249.0),它将在状态栏中显示用户的StackOverflow / SuperUser / ServerFault信誉。我设计了一个选项页面以获取用户的配置文件ID,并将它们保存到localStorage并在扩展中很好地读取它们。这一切都很好。

问题是我找不到一个(编程)方式来刷新选项保存的扩展名。我试图在右击它时从扩展页面本身调用 location.reload(); - 无济于事。我进一步追踪,并试图查看Chrome的 chrome:// extensions / 页面是否会重新加载扩展程序,并发现此代码:

  / ** 
*处理点击重新加载按钮。
* /
函数handleReloadExtension(node){
//告诉C ++ ExtensionDOMHandler重新加载扩展。
chrome.send('reload',[node.extensionId]);
}

将此代码复制到我的事件处理程序中并没有帮助(是的,我尝试过用实际的代码替换 [node.extensionId] )。有人可以帮助我以正确的方式做到这一点,或者指出我的扩展代码是否正确?完成之后,我会将扩展和源代码放到我的博客上。 解决方案

chrome.send函数不可访问通过扩展的JavaScript代码,像newtab页面,历史记录和扩展页面这样的页面可以使用它来与这些页面的C ++控制器代码进行通信。

您可以将扩展程序的更新推送给安装它的用户,这是描述的这里。用户的应用程序将在自动更新间隔命中或重新启动浏览器时更新。但是,您不能以编程方式重新加载用户的扩展。我认为这会带来安全风险。

I'm developing an extension in Chrome 4 (currently 4.0.249.0) that will show the user's StackOverflow/SuperUser/ServerFault reputation in the status bar. I've designed an options page to get the user's profile IDs and I save them to localStorage and read them well in the extension. It all works great.
The problem is I cannot find a (programmatic) way to refresh the extension upon options saving. I tried calling location.reload(); from the extension page itself upon right clicking it - to no avail. I pursued it further and tried looking at what Chrome's chrome://extensions/ page does to reload an extension, and found this code:

/**
 * Handles a 'reload' button getting clicked.
 */
function handleReloadExtension(node) {
  // Tell the C++ ExtensionDOMHandler to reload the extension.
  chrome.send('reload', [node.extensionId]);
}

Copying this code to my event handler did not help (and yes, I tried replacing [node.extensionId] with the actual code). Can someone please assist me in doing this the right way, or pointing me at a code of an extension that does this correctly? Once done, I'll put the extension and its source up on my blog.

解决方案

The chrome.send function is not accessible by your extension's javascript code, pages like the newtab page, history and the extensions page use it to communicate with the C++ controller code for those pages.

You can push updates of your extension to users who have it installed, this is described here. The user's application will be updated once the autoupdate interval is hit or when they restart the browser. You cannot however reload a user's extension programmatically. I think that would be a security risk.

这篇关于如何刷新/重新加载Chrome扩展程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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