未定义的响应:从Chrome应用程序向Chrome扩展程序发送消息

时间:2017-09-30 22:05:41

标签: javascript google-chrome google-chrome-extension google-chrome-app

我尝试从Chrome扩展程序请求数据库返回到Chrome应用程序。但回复论点"回复"记录为"未定义。"我在这里做错了吗?

扩展程序背景脚本代码段

chrome.runtime.onMessageExternal.addListener(
    function (request, sender, sendResponse) {

        console.log("RECIEVED REQUEST FROM APP");

        chrome.storage.local.get(lwsDatabaseName, function (storage) {

            if (lwsDatabaseName in storage) {

                console.log("SENDING THE DATABASE");
                console.log("SENDING: " + JSON.stringify(storage[lwsDatabaseName]));
                sendResponse({ data: storage[lwsDatabaseName] });

            } else {

                console.log("SENDING MESSAGE BACK TO APP");
                sendResponse({ spanish: "", english: "", context: "You haven't gathered any vocabulary yet! Select words in your browser to add them to your vocabulary.", hier: 0, timesViewed: 0, id: -1 });

            }

        });


    });

应用脚本代码段

chrome.runtime.sendMessage(vocabBrowserExtensionId, { action: "send_db" },
    function (response) {

        console.log("REPLY RECEIVED!");
        console.log(response.data);

        //Save db in app storage
        chrome.storage.local.get(dbName, function (storage) {

            storage[dbName] = response.data;

            chrome.storage.local.set(storage, function () {

                console.log("Card database saved!");
                callback.call(this);

            });

        });

    });

提前致谢!

0 个答案:

没有答案
相关问题