简体   繁体   中英

Chrome extension string encoding

[Edited after the answer below]

I'm fairly new to chrome extension. I'm using various chrome chrome.* apis ( eg chrome.tabs ).
Eg chrome.tabs.onUpdated.addListener( func ) notifies when a tab is updated. The call back function has Tab object which has various properties to the Title of the tab and URL and other information.

I would like to find out what string encoding does this strings have. The documentation says UTF-8. Documentation link

Does the chrome extension keep the same utf-8 encoding even when the webpage encoding is different ? Is there an chrome API to check for the encoding ?

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. 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

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.

The Chrome extension API is generally used with UTF-8. For instance, content scripts will not load if they are encoded in anything else other than UTF-8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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