简体   繁体   English

Chrome扩展程序字符串编码

[英]Chrome extension string encoding

[Edited after the answer below] [以下答案后编辑]

I'm fairly new to chrome extension. 我对chrome扩展还很陌生。 I'm using various chrome chrome.* apis ( eg chrome.tabs ). 我正在使用各种chrome chrome。* API(例如chrome.tabs)。
Eg chrome.tabs.onUpdated.addListener( func ) notifies when a tab is updated. 例如,chrome.tabs.onUpdated.addListener(func)会在标签页更新时发出通知。 The call back function has Tab object which has various properties to the Title of the tab and URL and other information. 回调函数具有Tab对象,该对象具有选项卡的标题和URL以及其他信息的各种属性。

I would like to find out what string encoding does this strings have. 我想找出这个字符串有什么字符串编码。 The documentation says UTF-8. 该文件说UTF-8。 Documentation link 文档链接

Does the chrome extension keep the same utf-8 encoding even when the webpage encoding is different ? 即使网页编码不同,chrome扩展程序也会保持相同的utf-8编码吗? Is there an chrome API to check for the encoding ? 是否有chrome API可以检查编码?

I ask this because I want to send these strings to a remote process through Native Messaging Host. 我问这个问题是因为我想通过本地消息传递主机将这些字符串发送到远程进程。 Pack the data in json string and send it across. 将数据打包为json字符串并发送出去。 It appears I'll have to send the encoding information as well if the encoding depends on web page encoding. 如果编码取决于网页编码,则似乎也必须发送编码信息。

In the scope of native messaging, you can assume that the strings are UTF-8 encoded, because the the native messaging protocol explicitly states that 在本机消息传递的范围内,您可以假定字符串是UTF-8编码的,因为本机消息传递协议明确指出:

The same format is used to send messages in both directions: each message is serialized using JSON, UTF-8 encoded and is preceded with 32-bit message length in native byte order. 双向使用相同的格式来发送消息:每条消息都使用JSON( UTF-8编码 )进行序列化,并以本机字节顺序开头32位消息长度。

The Chrome extension API is generally used with UTF-8. Chrome扩展API通常与UTF-8一起使用。 For instance, content scripts will not load if they are encoded in anything else other than UTF-8. 例如,如果内容脚本使用UTF-8以外的任何其他格式编码,则它们不会加载。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM