javascript - Chrome extension : Storing variables for a tab even if page changes -



javascript - Chrome extension : Storing variables for a tab even if page changes -

i building chrome extension. wondering if there way remember js variables tab if page changes. eg. if on example1.com , go example2.com on same tab, should retain variables set on example1.com. don't want utilize chrome storage.

i can't utilize localstorage or sessionstorage because chrome has different storages different domains. ways can accomplished ?

apart using localstorage( through background page), can straight save variables in background page messaging content script background page. if variables in extension page(other content or injected scripts) can save them chrome.extension.getbackgroundpage().window.variableyouwant method , access variables in content script messaging. if variables in content script utilize messaging send variables background page this:

chrome.runtime.sendmessage(object);

object object might want send.

on background page have lisner this:

chrome.runtime.onmessage.addlistener(function(message, sender, sendresponse) { myvariabeinbackground = message.yourobjectproperties; });

when require variables can utilize chrome.extension.getbackgroundpage().window.myvariabeinbackground in extension page(other content script) or can send message background page content script calling chrome.tabs.sendmessage(tabid, messageobject) in background page , receive @ content script having listner this:

chrome.runtime.onmessage.addlistener( function(request, sender) {}); //request sent object.

for localstorage can same thing stored variable content script. , no, cant straight access background page content script.

ps: variables in background page reset if extension reloaded. if want utilize variables after reloading extension utilize local storage. extension not reload on browser actions. more details read https://developer.chrome.com/extensions/messaging

javascript jquery google-chrome-extension storage

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -