I am facing an issue with storing a list of values in Chrome's local storage for a Chrome extension. I am trying to use the URL as the key in the key-value store, but for some reason, the set()
function fails when using a URL as a key. Surprisingly, when I use a random string like "hello"
, everything works fine.
Could there be a restriction on using URLs as keys? I couldn't find any mention of such a restriction in the API documentation.
It's important to mention that Chrome is not setting runtime.lastError
, the issue arises when I try to retrieve a key that was previously set with a URL using the get()
method.
Here is the code snippet for reference:
function addNode(url, referrer) {
nodes = chrome.storage.local;
edge = {
in_node: referrer,
timestamp: Date()
};
nodes.get(url, function(current_node){
console.log(current_node);
if ( $.isEmptyObject(current_node) === false ) {
// This block never executes because the set method doesn't work
}
else {
console.log("set: "+url);
nodes.set({url:[edge]}, function(){
if ( chrome.runtime.lastError ) {
console.log(chrome.runtime.lastError);
}
else {
console.log("get: "+url);
chrome.storage.local.get(url, function(thing) {console.log(thing)});
console.log("Created new Node for url " + url + " and new edge from " + edge.in_node + " at time " + edge.timestamp);
}
});
}
});
}