我想为我的chrome扩展重新加载每次我保存在扩展文件夹中的文件,而不必显式点击“重新加载”在chrome://extensions/。这可能吗?

编辑:我知道我可以更新Chrome重新加载扩展的间隔,这是一个中途的解决方案,但我宁愿让我的编辑器(emacs或textmate)触发保存重新加载或要求Chrome监控目录的变化。


当前回答

正如文档中提到的:下面的命令行将重新加载应用程序

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --load-and-launch-app=[path to the app ]

所以我只是创建了一个shell脚本,并从gulp调用该文件。超级简单:

var exec = require('child_process').exec;



gulp.task('reload-chrome-build',function(cb){

console.log("reload");

var cmd="./reloadchrome.sh"

exec(cmd,function (err, stdout, stderr) {
    console.log("done: "+stdout);

    cb(err);
    }
);});

在脚本上运行必要的监视命令,并在需要时调用重载任务。干净,简单。

其他回答

是的,你可以间接地做!这是我的解决方案。

在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);
})();

注入的脚本可以从任何位置注入其他脚本。

这种技术的另一个好处是你可以忽略孤立世界的限制。参见内容脚本执行环境

如果你有一台Mac,最简单的方法就是使用Alfred App!

只需使用Powerpack获取Alfred App,然后添加下面链接中提供的工作流,并自定义你想要的热键(我喜欢使用⌘+ + R)。

现在,每次你使用热键,谷歌Chrome浏览器将重新加载,无论你在那个时刻的应用程序。

如果你想使用其他浏览器,打开AppleScript在阿尔弗雷德首选工作流程和替换“谷歌Chrome”与“Firefox”,“Safari”,…

我还将在这里显示在ReloadChrome中使用的/usr/bin/osascript脚本的内容。Alfredworkflow文件,这样你就可以看到它在做什么。

tell application "Google Chrome"
  activate
  delay 0.5
  tell application "System Events" to keystroke "r" using command down
  delay 0.5
  tell application "System Events" to keystroke tab using command down
end tell

工作流文件为ReloadChrome.alfredworkflow。

你可以使用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上使用。

mozilla的家伙们刚刚发布了一个新的https://github.com/mozilla/web-ext,你可以用它来启动web-ext运行——target chromium

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窗口打开只是为了重新加载)。

(疯狂至极,但可能管用)