2022-01-19 js 和 native 傳輸字符串過長問題

js 傳輸過長的問題

https://bugs.chromium.org/p/chromium/issues/detail?id=884100

Hi Huawei Team:This is an intended behavior , which means developers may using the wrong API.For your reference, the change was made here: https://chromium-review.googlesource.com/c/chromium/src/+/1112471In short, developers should not rely on prompt() as a means of passing data from JS to Java. There are other APIs that are properly suited to this task. If the message is that long (even longer than 10240 bytes), Ideally you should use the postMessage APIs, or addJavascriptInterface (which has a lower minsdk). You can also use the androix.webkit support library to expand the coverage of postMessage.@JavascriptInterface methods and postMessage are the actual mechanisms for communicating data between your web code and native code; the limits there are determined just by the IPC implementation.The onJs* callbacks are intended solely to implement standard web browser style dialog boxes to communicate with the user, not for internal communication with your program, and they're subject to change as browsers' handling of these functions change (most browsers are treating these as legacy functions and restricting their usage).Best Regards!Guangwei

https://chromium-review.googlesource.com/c/chromium/src/+/1112471

Truncate JavaScript dialog message strings before IPC.

This moves message size metrics to be before IPC (and before
truncation) and removes three metrics.

JSDialogs.CountOfJSDialogMessageCharacters is removed;
JSDialogs.CharacterCount.MainFrame/Subframe is replacing it.

JSDialogs.CountOfJSDialogMessageNewlines is not useful as
we do rectangular truncation.

JSDialogs.CharacterCountUserSuppressed was just broken as it
was gated by "if (did_suppress_message)", and
"did_suppress_message" was a non-null bool pointer.

BUG=804081

if (is_main_frame_)
UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.MainFrame", message_length);
else
UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCount.Subframe", message_length);

// 10k ought to be enough for anyone.
const base::string16::size_type kMaxMessageSize = 10 * 1024;
base::string16 truncated_message = message.substr(0, kMaxMessageSize);

谷歌這個(gè)修改是解決這個(gè)804081的bug:
UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36

Steps to reproduce the problem:

  1. Open https://jsfiddle.net/ha0o2d67/
  2. Click "Choose file" and pick any file bigger than 100 Mb
  3. Wait few seconds

What is the expected behavior?
Tab isn't crashed

What went wrong?
Tab is crashed: Aw, Snap!

Did this work before? N/A

Does this work in other browsers? Yes

Chrome version: 63.0.3239.132 Channel: stable
OS Version: 10.0
Flash Version:

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末唆涝,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子唇辨,更是在濱河造成了極大的恐慌廊酣,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,427評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件赏枚,死亡現(xiàn)場離奇詭異亡驰,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)饿幅,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評論 3 395
  • 文/潘曉璐 我一進(jìn)店門凡辱,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人栗恩,你說我怎么就攤上這事透乾。” “怎么了磕秤?”我有些...
    開封第一講書人閱讀 165,747評論 0 356
  • 文/不壞的土叔 我叫張陵乳乌,是天一觀的道長。 經(jīng)常有香客問我市咆,道長汉操,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,939評論 1 295
  • 正文 為了忘掉前任蒙兰,我火速辦了婚禮磷瘤,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘癞己。我一直安慰自己膀斋,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評論 6 392
  • 文/花漫 我一把揭開白布痹雅。 她就那樣靜靜地躺著仰担,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上摔蓝,一...
    開封第一講書人閱讀 51,737評論 1 305
  • 那天赂苗,我揣著相機(jī)與錄音,去河邊找鬼贮尉。 笑死拌滋,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的猜谚。 我是一名探鬼主播败砂,決...
    沈念sama閱讀 40,448評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼魏铅!你這毒婦竟也來了昌犹?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,352評論 0 276
  • 序言:老撾萬榮一對情侶失蹤览芳,失蹤者是張志新(化名)和其女友劉穎斜姥,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體沧竟,經(jīng)...
    沈念sama閱讀 45,834評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡铸敏,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了悟泵。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片杈笔。...
    茶點(diǎn)故事閱讀 40,133評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖魁袜,靈堂內(nèi)的尸體忽然破棺而出桩撮,到底是詐尸還是另有隱情,我是刑警寧澤峰弹,帶...
    沈念sama閱讀 35,815評論 5 346
  • 正文 年R本政府宣布店量,位于F島的核電站,受9級特大地震影響鞠呈,放射性物質(zhì)發(fā)生泄漏融师。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評論 3 331
  • 文/蒙蒙 一蚁吝、第九天 我趴在偏房一處隱蔽的房頂上張望旱爆。 院中可真熱鬧,春花似錦窘茁、人聲如沸怀伦。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽房待。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間桑孩,已是汗流浹背拜鹤。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留流椒,地道東北人敏簿。 一個(gè)月前我還...
    沈念sama閱讀 48,398評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像宣虾,于是被迫代替她去往敵國和親惯裕。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評論 2 355

推薦閱讀更多精彩內(nèi)容