Last active
November 24, 2017 20:54
-
-
Save zachhardesty7/65ec4be9241980ed887fe143b7157c02 to your computer and use it in GitHub Desktop.
example chrome message passing (background)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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