我想为我的chrome扩展重新加载每次我保存在扩展文件夹中的文件,而不必显式点击“重新加载”在chrome://extensions/。这可能吗?
编辑:我知道我可以更新Chrome重新加载扩展的间隔,这是一个中途的解决方案,但我宁愿让我的编辑器(emacs或textmate)触发保存重新加载或要求Chrome监控目录的变化。
我想为我的chrome扩展重新加载每次我保存在扩展文件夹中的文件,而不必显式点击“重新加载”在chrome://extensions/。这可能吗?
编辑:我知道我可以更新Chrome重新加载扩展的间隔,这是一个中途的解决方案,但我宁愿让我的编辑器(emacs或textmate)触发保存重新加载或要求Chrome监控目录的变化。
当前回答
你可以使用Chrome的“Extensions Reloader”:
Reloads all unpacked extensions using the extension's toolbar button or by browsing to "http://reload.extensions" If you've ever developed a Chrome extension, you might have wanted to automate the process of reloading your unpacked extension without the need of going through the extensions page. "Extensions Reloader" allows you to reload all unpacked extensions using 2 ways: 1 - The extension's toolbar button. 2 - Browsing to "http://reload.extensions". The toolbar icon will reload unpacked extensions using a single click. The "reload by browsing" is intended for automating the reload process using "post build" scripts - just add a browse to "http://reload.extensions" using Chrome to your script, and you'll have a refreshed Chrome window.
更新:截至2015年1月14日,扩展是开源的,可在GitHub上使用。
其他回答
作者推荐该webpack插件的下一个版本:https://github.com/rubenspgcavalcante/webpack-extension-reloader。这对我来说很有效。
也许回答得有点晚,但我认为crxreload可能对你有用。这是我在开发时尝试重新加载保存工作流的结果。
Chrome扩展有一个权限系统,它不会允许它(一些人在SO有同样的问题),所以要求他们“添加这个功能”是不会工作的IMO。有一封来自Chromium Extensions谷歌Groups的邮件,其中提出了一个使用Chromium .extension. getviews()的解决方案(理论),但也不能保证工作。
是否可以加到清单上。json一些Chrome内部页面,如Chrome://extensions/,这将有可能创建一个插件,将与Reload锚交互,并使用外部程序,如XRefresh(一个Firefox插件-有一个Chrome版本使用Ruby和WebSocket),你将实现你所需要的:
XRefresh是一个浏览器插件 是否会刷新当前网页 所选文件夹中的文件更改。这 使它有可能做活页 使用您最喜欢的HTML/CSS编辑 编辑器。
这是不可能做到的,但我认为你可以用不同的方式来使用这个概念。
您可以尝试找到第三方解决方案,而不是,在看到文件中的修改后(我不知道emacs也不知道Textmate,但在emacs中可以绑定一个应用程序调用“保存文件”动作),只需单击特定应用程序的特定坐标:在这种情况下,它是从您的扩展在开发中的重新加载锚(您留下一个Chrome窗口打开只是为了重新加载)。
(疯狂至极,但可能管用)
是的,你可以间接地做!这是我的解决方案。
在manifest.json
{
"name": "",
"version": "1.0.0",
"description": "",
"content_scripts":[{
"run_at":"document_end",
"matches":["http://*/*"],
"js":["/scripts/inject.js"]
}]
}
在inject.js
(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = 'Your_Scripts';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(script, s);
})();
注入的脚本可以从任何位置注入其他脚本。
这种技术的另一个好处是你可以忽略孤立世界的限制。参见内容脚本执行环境
我想一夜之间重新加载(更新)我的扩展,这是我在background.js中使用的:
var d = new Date();
var n = d.getHours();
var untilnight = (n == 0) ? 24*3600000 : (24-n)*3600000;
// refresh after 24 hours if hour = 0 else
// refresh after 24-n hours (that will always be somewhere between 0 and 1 AM)
setTimeout(function() {
location.reload();
}, untilnight);
问候, 彼得