chrome.runtime.sendMessage显示错误“消息长度超出允许的最大长度”

时间:2018-01-20 12:08:52

标签: javascript jquery google-chrome-extension

当我使用chrome.runtime.sendMessage从content.js向background.js发送大尺寸的json对象时,显示如下错误:

this post

错误是:未捕获错误:消息长度超出了允许的最大长度。

如果有人知道如何在manifest.json文件中增加sendmessage参数maxsize。

Content.js

var ServerPath = "http://localhost:62513/api/account";
    chrome.runtime.sendMessage({
        method: 'POST',
        action: 'xhttp',
        url: ServerPath + "/rapdata",
        data: JSON.stringify({ data: data, fileName: fileName })
    }, function (responseText) {
        //alert(responseText);
        console.log("response of call saverapdata method");
        /*Callback function to deal with the response*/
    });

Background.js

chrome.runtime.onMessage.addListener(function (request, sender, callback) {
    console.log("background js onMessage call.");
    var resp = "done";
    if (request.action == "xhttp") {
        debugger;
        //alert(request.data);url: ServerPath + "/rapdata",
        var ServerPath = "http://localhost:62513/api/account";
        $.ajax({
            type: "POST",
            url: request.url,
            data: request.data,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                debugger;
                console.log(data);
                //alert("Data: " + data);
            },
            failure: function (response) {
                debugger;
                console.log(response);
                ///alert(response.d);
            }
        });
        return true; // prevents the callback from being called too early on return
    }
});

0 个答案:

没有答案