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

后端 未结 1 1622
独厮守ぢ
独厮守ぢ 2021-01-12 05:17

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

相关标签:
1条回答
  • 2021-01-12 05:55

    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.

    0 讨论(0)
提交回复
热议问题