Skip to content

Instantly share code, notes, and snippets.

@zachhardesty7
Last active November 24, 2017 20:54
Show Gist options
  • Save zachhardesty7/65ec4be9241980ed887fe143b7157c02 to your computer and use it in GitHub Desktop.
Save zachhardesty7/65ec4be9241980ed887fe143b7157c02 to your computer and use it in GitHub Desktop.
example chrome message passing (background)
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
// listen for messages
if (request.type === 'fromContent') {
// use own func to process (or just store directly)
let data = processData(request.data);
localStorage.setItem(request.key, JSON.stringify(data));
} else if (request.type == 'fromPopup') {
let data = JSON.parse(localStorage.getItem(request.key));
sendResponse({
data: data
});
}
// should be included by default
return true;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment