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

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


当前回答

我已经做了一个简单的可嵌入脚本热重载:

https://github.com/xpl/crx-hotreload

它监视扩展名目录中的文件更改。当检测到更改时,它重新加载扩展并刷新活动选项卡(以重新触发更新的内容脚本)。

通过检查文件的时间戳来工作 支持嵌套目录 在生产配置中自动禁用自身

其他回答

我主要在Firefox中开发,其中web-ext运行会在文件更改后自动重新加载扩展。一旦准备就绪,我会在Chrome中进行最后一轮测试,以确保没有Firefox中没有出现的任何问题。

如果你想主要在Chrome上开发,并且不想安装任何第三方扩展,那么另一个选择是在扩展的文件夹中创建一个test.html文件,并添加一堆SSCCE。然后,该文件使用一个正常的<script>标记来注入扩展脚本。

您可以使用它进行95%的测试,然后当您想在现场测试它时手动重新加载扩展。

这并不能完全重现扩展所运行的环境,但对于许多简单的事情来说已经足够好了。

BROWSER-SYNC

使用惊人的浏览器同步

更新浏览器(任何)当源代码改变(HTML, CSS,图像等) 支持Windows、MacOS和Linux操作系统 您甚至可以使用移动设备观看您的代码更新(实时)

MacOS上的安装(查看其他OS上的安装帮助)

安装NVM,这样您就可以尝试任何Node版本

brew install nvm             # install a Node version manager
nvm ls-remote                # list available Node versions
nvm install v10.13.0         # install one of them
npm install -g browser-sync  # install Browser-Sync

如何使用浏览器同步静态网站

让我们来看两个例子:

browser-sync start --server --files . --host YOUR_IP_HERE --port 9000

browser-sync start --server --files $(ack --type-add=web:ext:htm,html,xhtml,js,css --web -f | tr \\n \ ) --host $(ipconfig getifaddr en0) --port 9000

——server选项允许您在终端的任何地方运行本地服务器,而——files选项允许您指定将跟踪哪些文件的更改。我更喜欢对跟踪的文件更具体,因此在第二个示例中,我使用ack来列出特定的文件扩展名(重要的是这些文件没有带空格的文件名),并使用useipconfig来查找我在MacOS上的当前IP。

如何使用浏览器同步动态网站

如果您正在使用PHP、Rails等,您已经有一个正在运行的服务器,但是当您更改代码时它不会自动刷新。所以你需要使用——proxy开关让browser-sync知道该服务器的主机在哪里。

browser-sync start --files $(ack --type-add=rails:ext:rb,erb,js,css,sass,scss,coffee --rails -f | tr \\n \ ) --proxy 192.168.33.12:3000 --host $(ipconfig getifaddr en0) --port 9000 --no-notify --no-open

在上面的例子中,我已经在浏览器的192.168.33.12:3000上运行了一个Rails应用程序。它实际上运行在使用Vagrant盒子的虚拟机上,但我可以使用该主机上的端口3000访问虚拟机。我喜欢——no-notify来停止浏览器同步,每次我修改代码时,都会在浏览器上发送通知警报,——no-open来停止浏览器同步行为,当服务器启动时立即加载浏览器选项卡。

重要提示:如果您正在使用Rails,请避免在开发中使用Turbolinks,否则在使用——proxy选项时将无法单击链接。

希望对别人有用。我尝试了许多技巧来刷新浏览器(甚至是我之前使用AlfredApp提交的关于这个StackOverflow问题的旧帖子),但这是真正的方法;没有更多的黑客,它只是流动。

CREDIT:用一个命令启动本地实时重载web服务器

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

使用npm init创建一个包。Json在根目录下

NPM install——save-dev gulp-open &&

然后创建gulpfile.js

它看起来像:

/* File: gulpfile.js */

// grab our gulp packages
var gulp  = require('gulp'),
    open = require('gulp-open');

// create a default task and just log a message
gulp.task('default', ['watch']);

// configure which files to watch and what tasks to use on file changes
gulp.task('watch', function() {
  gulp.watch('extensionData/userCode/**/*.js', ['uri']);
});

gulp.task('uri', function(){
  gulp.src(__filename)
  .pipe(open({uri: "http://reload.extensions"}));
});

这适用于我开发CrossRider,你可能会观察改变路径,你看文件在,也假设你有npm和节点安装。

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