Mehul Prajapati

Mehul Prajapati

  • NA
  • 1.3k
  • 44.3k

chrome.runtime.sendMessage error “Message length exceeded”

Jan 20 2018 7:43 AM
When i am sending big size of json object from content.js to background.js usingchrome.runtime.sendMessage then showing error like
 
Error is : Uncaught Error: Message length exceeded maximum allowed length.
Content.js
  1. var ServerPath = "http://localhost:62513/api/account";  
  2. chrome.runtime.sendMessage({  
  3. method: 'POST',  
  4. action: 'xhttp',  
  5. url: ServerPath + "/rapdata",  
  6. data: JSON.stringify({ data: data, fileName: fileName })  
  7. },function (responseText) {  
  8. //alert(responseText);  
  9. console.log("response of call saverapdata method");  
  10. /*Callback function to deal with the response*/  
  11. });  
Background.js
  1. chrome.runtime.onMessage.addListener(function (request, sender, callback) {  
  2. console.log("background js onMessage call.");  
  3. var resp = "done";  
  4. if (request.action == "xhttp") {  
  5. debugger;  
  6. //alert(request.data);url: ServerPath + "/rapdata",  
  7. var ServerPath = "http://localhost:62513/api/account";  
  8. $.ajax({  
  9. type: "POST",  
  10. url: request.url,  
  11. data: request.data,  
  12. contentType: "application/json; charset=utf-8",  
  13. dataType: "json",  
  14. success: function (data) {  
  15. debugger;  
  16. console.log(data);  
  17. //alert("Data: " + data);  
  18. },  
  19. failure: function (response) {  
  20. debugger;  
  21. console.log(response);  
  22. ///alert(response.d);  
  23. }  
  24. });  
  25. return true// prevents the callback from being called too early on return  
  26. }  
  27. });  

Answers (1)