是否有大小限制像32字节或64字节?内容脚本和后台网页之间传递的Chrome扩展的消息? [英] Is there a size limit like 32bytes or 64Bytes? for message passing between content scripts and background pages for chrome extensions?

查看:312
本文介绍了是否有大小限制像32字节或64字节?内容脚本和后台网页之间传递的Chrome扩展的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Chrome扩展,从网页拉大的公共密钥。我需要知道我是否会碰上,我不能在谷歌网站上,涉及到他们的消息传递API找到任何限制。

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.

谢谢!

推荐答案

当您使用 chrome.runtime.sendMessage ,消息被序列化,并从发送者的发送过程(例如包含内容脚本选项卡)来扩展的过程(背景页)中一气呵成。该IPC消息的硬限制是<一个href=\"https://chromium.googlesource.com/chromium/src/+/a09b9be79387f1107ba29c5f7b0051168193d958/ipc/ipc_channel.h#92\">128 MB 的。如果您发送什么比这更大,发件人的过程将被终止。

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.

现在,邮件大小为128 MB,并不意味着你可以发送长度为134217728的一个JavaScript字符串,因为消息本身也需要一定的空间来存储元数据。和在JavaScript字符串的字符数不是必需的字节数(假设平均组成的任意字符的JavaScript字符串每个字符要求2字节的存储空间)。这使下最高限额为50 MB。

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.

虽然50 MB在技术上是可以接受的,你不应该尝试发送这么多的数据。下面是Chrome的任务管理器的启动浏览器和发送数据的50MB之后的截图。图为,它花了5秒钟就可以从标签到背景页邮件,浏览器和标签的过程均约300MB和推广过程663MB(其中初始值分别为32,17和22 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.

这篇关于是否有大小限制像32字节或64字节?内容脚本和后台网页之间传递的Chrome扩展的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆