So I am currently making a chrome extension that allows you to set shortcuts to websites and go to them directly. But for some reason I am currently, here, getting undefined at the command1
Here is the code:
let current_url = document.getElementsByClassName("current_url");
let bg = chrome.extension.getBackgroundPage();
let url = ""
let storage = chrome.storage.sync
console.log(chrome)
console.log(bg)
console.log(bg.command1)
function adder(){
    for(elt of current_url) {
       switch(elt.innerHTML) {
           case "command1":
               chrome.storage.sync.get("key1", function(msg){url = msg.key1.toString(); console.log(msg.key1)});
               break;
           case "command2":
                 url = bg.command2;
                break;
           case "command3":
                url = bg.command3;
               break;
            case "command4":
                url = bg.command4;
                break;
       }
       elt.innerHTML = `${elt.innerHTML}       ${url}`;
       console.log(elt)
    }
}
adder().change-c{
    margin: 20px;
    background-color: grey;
    list-style: none;
}<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <script defer src= "app.js"></script>
</head>
<body>
    <ul class= "change-c">
        <p class= "current_url">command1</p><li><input type="text" class="enter"></li>
    </ul>
    <ul class="change-c">
        <p class= "current_url">command2</p><li><input type="text" class="enter"></li>
    </ul>
    <ul class="change-c">
        <p class= "current_url">command3</p><li><input type="text" class="enter"></li>
    </ul>
    <ul class= "change-c">
        <p class= "current_url">command4</p><li><input type="text" class="enter"></li>
    </ul>
    
</body>
</html>So any ideas why this is happening? Like at console.log("msg.key1") it does say "https://www.youtube.com"  but the variable "url" is undefined even though they are the same. Please help if u can

 
     
    