I am not very familiar with that, but you can take a look at the source code of the Chrome extension.