Chrome扩展程序访问站点cookie未经检查的runtime.lastError:消息端口在收到响应之前已关闭

时间:2019-07-08 03:23:11

标签: google-chrome google-chrome-extension

访问content.js中的cookie

    chrome.runtime.sendMessage(
        {
            type: "getAllCookies",
            data: {}
        },
        function callback(cookies) {
            console.log(cookies);
        }
    );

background.js

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    switch (request.type) {
        case "getAllCookies":
            chrome.cookies.getAll(
                {
                    domain: "xxx"
                },
                function(cookies) {
                    sendResponse(cookies);
                }
            );
            break;
    }
});

回调返回未定义,控制台显示以下错误

Unchecked runtime.lastError: The message port closed before a response was received.

Chrome版本:75.0.3770.100 x64

如何访问Chrome扩展程序中的Cookie?

0 个答案:

没有答案