Im building extension which based on user input and saving, will be opening links based on some conditions. Im using chrome.storage.sync.set, everything works fine. I need to create var from data stored by chrome.storage.sync.get. I am storing URLs.
Storing:
function save_options() {
var d = document.getElementById('text').value
chrome.storage.sync.set({
"data": d,
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}
document.getElementById('set').addEventListener('click',
save_options);
Retrieving: This will retrieve stored value and show it on settings page like text, so user knows what data has been stored.
function() {
chrome.storage.sync.get("data", function(items) {
if (!chrome.runtime.error) {
console.log(items);
document.getElementById("data").innerText = items.data;
}
});
}
But when I try to do same thing, retrieve data and create var, Im having only opened empty links:
function visit() {
var f = chrome.storage.sync.get("data");
window.open(f);
}
Even tried creating global var:
var f;
function visit() {
f = chrome.storage.sync.get("data");
window.open(f);
}
Thank you for your advice.