简体   繁体   English

是否有像32bytes或64Bytes这样的大小限制? 在内容脚本和chrome扩展的后台页面之间传递消息?

[英]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. 我正在开发一个chrome扩展,从网页中提取大型公钥。 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. 我需要知道我是否会遇到谷歌网站上与他们的消息传递API相关的任何限制。

Thanks! 谢谢!

When you use chrome.runtime.sendMessage , the message is serialized, and sent from the sender's process (eg the tab containing the content script) to the extension's process (the background page) in one go. 当您使用chrome.runtime.sendMessage ,邮件将被序列化,并从发件人的进程(例如包含内容脚本的选项卡)一次性发送到扩展程序的进程(后台页面)。 The hard limit of the IPC message is 128 MB . IPC消息的硬限制为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. 现在,消息大小为128 MB并不意味着您可以发送长度为134,217,728的JavaScript字符串,因为消息本身也需要一些空间来存储元数据。 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). 并且JavaScript字符串中的字符数不一定是字节数(假设平均而言,由任意字符组成的JavaScript字符串每个字符需要2个字节的存储空间)。 This brings down the maximum limit to 50 MB. 这将最大限制降低到50 MB。

Although 50 MB is technically acceptable, you should not try to send so much data. 虽然技术上可以接受50 MB,但您不应该尝试发送这么多数据。 Here is a screenshot of Chrome's task manager right after starting up the browser and sending 50MB of data. 以下是Chrome启动浏览器并发送50MB数据后的任务管理器的屏幕截图。 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). 图片显示,从标签页到背景页需要5秒钟,浏览器和标签处理都使用大约300MB和扩展过程663MB(其中初始值分别为32,17和22 MB) )。

Messages of a few megabytes are not a problem, however. 但是,几兆字节的消息不是问题。

任务管理器:293MB浏览器,281MB标签,663MB扩展名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 邮件从内容脚本传递到Chrome扩展程序中的后台页面 - Message Passing from Content Scripts to Background Page in Chrome Extensions 在内容脚本和后台页面之间传递消息 - Message passing between content scripts and background page Chrome 扩展中的后台脚本与内容脚本 - Background Scripts vs Content Scripts in Chrome Extensions Chrome扩展程序消息在内容和背景之间传递 - Chrome extension message passing between content and background 两个内容脚本之间传递的消息(通过后台) - Message passing between two content scripts (through background) 浏览器操作,后台脚本和chrome扩展的内容脚本之间的通信的上下文和方法? - Contexts and methods for communication between the browser action, background scripts, and content scripts of chrome extensions? 从Chrome扩展程序中的内容脚本传递消息 - Passing message from content script in Chrome extensions 内容和背景之间传递的Chrome扩展程序消息无效 - Chrome extension message passing between content and background not working Chrome 扩展消息在后台和内容脚本之间传递 - Chrome Extension Message Passing between background and content script 如何更改后台文件(Chrome扩展程序)中的content_scripts? - How to change the content_scripts in background file (Chrome Extensions)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM