Skip to content

Instantly share code, notes, and snippets.

@astromme
Created July 9, 2017 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astromme/296a3e4b391a170676ecde1ee62f58e5 to your computer and use it in GitHub Desktop.
Save astromme/296a3e4b391a170676ecde1ee62f58e5 to your computer and use it in GitHub Desktop.
Code to auto reload a chrome extension during development by watching a livereload server
// Credit goes to https://github.com/yeoman/generator-chrome-extension
// Reload client for Chrome Apps & Extensions.
// The reload client has a compatibility with livereload.
// WARNING: only supports reload command.
var LIVERELOAD_HOST = 'localhost:';
var LIVERELOAD_PORT = 35729;
var connection = new WebSocket('ws://' + LIVERELOAD_HOST + LIVERELOAD_PORT + '/livereload');
connection.onerror = function (error) {
console.log('reload connection got error:', error);
};
connection.onmessage = function (e) {
if (e.data) {
var data = JSON.parse(e.data);
if (data && data.command === 'reload') {
chrome.runtime.reload();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment