Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 847
Siddartha Avatar asked Aug 10 '15 17:08

Siddartha


1 Answers

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.

task manager: 293MB browser, 281MB tab, 663MB extension

like image 109
Rob W Avatar answered Nov 11 '22 19:11

Rob W