Created
January 31, 2011 04:11
-
-
Save mohamedmansour/803631 to your computer and use it in GitHub Desktop.
Get and Set localStorage from Content Script
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
// Content Script to save data. | |
chrome.extension.sendRequest({storage: 'foo', value: 'bar'}); | |
// Content Script to get data. | |
chrome.extension.sendRequest({storage: 'foo'}, function(response) { | |
console.log('foo => ' + response.storage); | |
}); | |
// Background Page | |
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { | |
if (request.storage) { | |
if (typeof request.value != 'undefined') { | |
localStorage[request.storage] = request.value; | |
} | |
sendResponse({storage: localStorage[request.storage]}); | |
} else { | |
sendResponse({}); | |
} | |
}); |
Can I get access to any localStorage ? I need to extract data from site with my domain.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anyone comes across this,
chrome.extension.sendRequest
is (long since) deprecated. You need to usechrome.runtime.sendMessage
andchrome.runtime.onMessage
. The signature is the same.