javascript - How to read configuration set in option page from content_scripts of Chrome extension? -


using localstorage, try store users configs, , works well.

// in options_page localstorage.setitem('mykey',someval); 

but it's difficult read configs content_scripts (´・ω・`)

localstorage.getitem('mykey'); // because different 'window' scope 

i'm making using runtime.sendmessage

// in content_scripts chrome.runtime.sendmessage(null, {purpose:'getconfig',configkey:'mykey'},     function(confhere){         // action     } ); 

i think it's complex!! (and using 'chrome.storage' requires permission, ugly) there way read configs content_scripts of chrome extension?

content scripts run within context of pages sharing dom , not extension. so, content script trying read localstorage read localstorage of page, , not extension.

the way proposed correct , far know best way access setting info in content script. so, when content script created send message background settings (as have done) , in background add listener return settings. it's not super clean ... intuitive when think of content scripts supposed (and not be).

here answer outlines need (although sounds of know must done :)) also, if interested content script page of extension docs has (and short) videos @ bottom helped me understand ideas behind content scripts should able do.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -