简体   繁体   English

镀铬扩展中未定义的 URL

[英]undefined URL in chrome extension

I'm making a simple extension that gets URL of the current tab and saves it to the storage when I click a 'create' button and retrieve URL when 'goto' button clicked.我正在制作一个简单的扩展程序,当我单击“创建”按钮并在单击“转到”按钮时检索 URL 时,获取当前选项卡的 URL 并将其保存到存储中。

I got undefined tab and url debugging this code.我得到了未定义的选项卡和 url 调试此代码。 I'm new to chrome extension and javascript and would appreciate your help: :)))我是 chrome 扩展和 javascript 的新手,不胜感激::)))

this is my popup.js这是我的 popup.js

$(function() {
    $('#create').click(function() {
        var tab;
        var myUrl;
        chrome.tabs.query({active: true, lastFocusedWindow: true}, function(tabs){
            tab = tabs[0];
            myUrl = tab.url;
        });

        chrome.storage.sync.set({'newUrl': myUrl});

    });
});

popup.html popup.html

 <script src= "jquery-3.4.1.min"></script>
    <script src = "popup.js"></script>;


</head>
<body>
    <input type = "button" id = "create" value = "create">
    <input type = "button" id = "go" value = "go to">
 </body>

manifest.json manifest.json

"permissions": [
    "tabs",
    "activeTab",
    "bookmarks",
    "contextMenus",
    "storage",
    "*://*/*"
],

chrome.* apis can be accessed from background and popup scripts only. chrome.* api 只能从后台和弹出脚本访问。 You have written those chrome.* api in injectedScript or content script.你已经写了那些chrome.* api 在注入脚本或内容脚本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM