Skip to content

HOWTO develop chrome extensions with auto reload

hbt edited this page Apr 1, 2012 · 1 revision

When it comes to developing chrome extensions, you can waste endless amount of hours reloading the extension after every change.

Your workflow looks something like this

  1. make a change in a file
  2. go to chrome://extensions/
  3. click "reload"
  4. reload your tab
  5. change appears then back to 1

Instead we came up with a small hack to automatically reload the extension after a file has been changed.


How it works:

  • a script watches the vrome directory for file changes
  • whenever a file is modified, the script updates a temporary file to indicate we have a change
  • in chrome://extensions/ we open the developer tools console (CTRL + Shift + J), we then insert a function. The function makes an ajax call every X milliseconds to the server
  • The server will return the value from the temporary file
  • When that value changes, the extension is reload via Javascript

Clear step by step instructions on how to make it work:

  1. install watch_and_do gem install watch_and_do -v 0.0.3
  2. go to root of project ~/vrome and start watching for changes using watch_and_do . js utils/update_version.rb Whenever a js file is modified, it will call the utils/update_version.rb script
  3. start the ruby server located in system/ruby/bin/vrome
  4. go to chrome://extensions/
  5. unpack the extension if it isn't already + make sure it is enabled
  6. open the developer tools console (CTRL + SHIFT + J)
  7. copy/paste the content of reload_extension.js in utils
  8. do not forget to modify the extensionID variable (view reload_extension.js script)
  9. You can now test it by making a change in one of the JS file. watch_and_do will report the change and update the version number then the code in the console in chrome://extensions/ will call the server and reload the extension
  10. Develop chrome extensions efficiently

Please note you can use something other than watch_and_do e.g inotifywatch to watch for file changes

Please also note that you still have to reload the tab -- maybe that's something we could automate too.