当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Is there a size limit like 32bytes or 64Bytes? for message passing between content scripts and background pages for chrome extensions?

问题描述:

I am developing a chrome extension that pulls large public keys from webpages. I need to know if I will run into any limitations that I can not find on googles website that relate to their message passing API.

Thanks!

网友答案:

When you use chrome.runtime.sendMessage, the message is serialized, and sent from the sender's process (e.g. the tab containing the content script) to the extension's process (the background page) in one go. The hard limit of the IPC message is 128 MB. If you send anything bigger than that, the sender's process will be terminated.

Now, the message size being 128 MB does not mean that you can send a JavaScript string of length 134,217,728, because the message itself also needs some space to store metadata. And the number of characters in a JavaScript string is not necessary the number of bytes (assume that on average, a JavaScript string consisting of arbitrary characters require 2 bytes storage per character). This brings down the maximum limit to 50 MB.

Although 50 MB is technically acceptable, you should not try to send so much data. Here is a screenshot of Chrome's task manager right after starting up the browser and sending 50MB of data. The picture shows that it took 5 seconds to get the message from the tab to the background page, and that the browser and tab process both use about 300MB and the extension process 663MB (where the initial values were 32, 17 and 22 MB, respectively).

Messages of a few megabytes are not a problem, however.

分享给朋友:
您可能感兴趣的文章:
随机阅读: