<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic The difference between Firefox and Chromium about keyup event in Discussions</title>
    <link>https://connect.mozilla.org/t5/discussions/the-difference-between-firefox-and-chromium-about-keyup-event/m-p/57578#M20232</link>
    <description>&lt;P&gt;This is part of the script code I used in Tampermonkey:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function addQuickChatBar(){
    let quickChatBarHtml = `
        &amp;lt;div class="quick-chat-bar-wrapper ele-hide"&amp;gt;
            &amp;lt;div class="quick-chat-input-wrapper"&amp;gt;
                &amp;lt;input id="quick-chat-input" type="text" autocomplete="off" placeholder="请输入弹幕,Enter键发送"/&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="quick-chat-input-count"&amp;gt;0/30&amp;lt;/div&amp;gt;
            &amp;lt;div class="quick-chat-send-btn" id="quick-chat-send-btn"&amp;gt;发送(enter)&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    `;
    $("#videoContainer").append(quickChatBarHtml);
    let wrapper = $(".quick-chat-bar-wrapper");
    let input = $("#quick-chat-input");
    $("#videoContainer").attr("tabindex","999").focus().keyup(e=&amp;gt;{
        let isFullPage = $(".player-narrowpage").size() &amp;gt; 0 || $(".player-narrowscreen").size() &amp;gt; 0;
        if(e.keyCode === 13){
            if(!wrapper.hasClass("ele-hide")){
                wrapper.toggleClass("ele-hide");
            } else if(isFullPage){
                wrapper.toggleClass("ele-hide");
                if(!wrapper.hasClass("ele-hide")){
                    input.focus();
                }
            }
            e.stopPropagation();
        }
    });

    let tooFast = false;
    let countInput = true;
    input.keyup(e=&amp;gt;{
        if(e.keyCode === 13){
            let text = input.val();
            if(text &amp;amp;&amp;amp; text.length &amp;gt; 0){
                if(!tooFast){
                    let sendTimeout = chat(text);
                    if(sendTimeout === 0){
                        wrapper.addClass("ele-hide");
                        $("#videoContainer").focus();
                        input.val("");
                        setInputCount(0);
                    } else {
                        tooFast = true;
                        $("#quick-chat-send-btn").toggleClass("div-disabled");
                        let disableTimer = setInterval(()=&amp;gt;{
                            if(sendTimeout &amp;gt; 0){
                                $("#quick-chat-send-btn").text(`倒计时:${sendTimeout}`);
                                sendTimeout--;
                            } else {
                                $("#quick-chat-send-btn").text("发送(enter)").toggleClass("div-disabled");
                                clearInterval(disableTimer);
                                tooFast = false;
                            }
                        }, 1000);
                    }
                }
            } else {
                wrapper.toggleClass("ele-hide");
                $("#videoContainer").focus();
            }
            e.stopPropagation();
        }
    }).on('compositionend', e =&amp;gt; {
        checkInputCount();
        setInputCount(input.val().length);
        countInput = true;
    }).on('input', e =&amp;gt; {
        if(countInput) {
            checkInputCount();
            setInputCount(input.val().length);
        }
    }).on('compositionstart', e =&amp;gt; {
        countInput = false;
    })

    let setInputCount = cnt =&amp;gt; $(".quick-chat-input-count").text(`${cnt}/30`);
    let checkInputCount = ()=&amp;gt;{
        let text = input.val();
        if(text.length &amp;gt;= 30) {
            input.val(text.substring(0, 30));
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I type some letters with Chinese input method, such as 'hhh' :&lt;/P&gt;&lt;P&gt;In chromium:&lt;/P&gt;&lt;P&gt;① When I type 'hhh', then p&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;ress the Enter key and release it immediately, it will input 'hhh' and don't send them. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;② When I type 'hhh', then press the Enter key &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;and hold&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt; for a while and then release it, it will input 'hhh' and send them. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;In Firefox:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;③ When I type 'hhh', then press the Enter key and release it immediately, it will input 'hhh' and send them. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Is this a Firefox bug?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Maybe the reason is there is monitor delays in chromium while Firefox not? &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Is there any settings in about:config to change ③ to ① ?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Expected behavior:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GIF 2024-5-20 20-37-16.gif" style="width: 614px;"&gt;&lt;img src="https://connect.mozilla.org/t5/image/serverpage/image-id/6375i6163BB1C90DD01B4/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="GIF 2024-5-20 20-37-16.gif" alt="GIF 2024-5-20 20-37-16.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Update：&lt;/P&gt;&lt;P&gt;Finally，I'm aware this is because Firefox &lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;responds to every keyup event independently, regardless of whether the keyup event is incidental to processing other tasks or not.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;such as this code：&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;input type="text" id="text"&amp;gt;
&amp;lt;script&amp;gt;
    document.getElementById("text").onkeyup = function(e) {
        alert("按键码: " + e.which + " 字符: " + String.fromCharCode(e.which));
    };
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Firefox, you cannot make this popup disappear by pressing the Enter key and releasing it immediately, while Chromium does allow it.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Misuzu_0-1716238267673.png" style="width: 400px;"&gt;&lt;img src="https://connect.mozilla.org/t5/image/serverpage/image-id/6379iC55A6B64246F0E17/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Misuzu_0-1716238267673.png" alt="Misuzu_0-1716238267673.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;In this case, the keyup event of the Enter key is incidental to compositionend, but Firefox still executes the keyup function regardless of that, while Chromium behaves as expected.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 20 May 2024 22:01:42 GMT</pubDate>
    <dc:creator>Misuzu</dc:creator>
    <dc:date>2024-05-20T22:01:42Z</dc:date>
    <item>
      <title>The difference between Firefox and Chromium about keyup event</title>
      <link>https://connect.mozilla.org/t5/discussions/the-difference-between-firefox-and-chromium-about-keyup-event/m-p/57578#M20232</link>
      <description>&lt;P&gt;This is part of the script code I used in Tampermonkey:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function addQuickChatBar(){
    let quickChatBarHtml = `
        &amp;lt;div class="quick-chat-bar-wrapper ele-hide"&amp;gt;
            &amp;lt;div class="quick-chat-input-wrapper"&amp;gt;
                &amp;lt;input id="quick-chat-input" type="text" autocomplete="off" placeholder="请输入弹幕,Enter键发送"/&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="quick-chat-input-count"&amp;gt;0/30&amp;lt;/div&amp;gt;
            &amp;lt;div class="quick-chat-send-btn" id="quick-chat-send-btn"&amp;gt;发送(enter)&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    `;
    $("#videoContainer").append(quickChatBarHtml);
    let wrapper = $(".quick-chat-bar-wrapper");
    let input = $("#quick-chat-input");
    $("#videoContainer").attr("tabindex","999").focus().keyup(e=&amp;gt;{
        let isFullPage = $(".player-narrowpage").size() &amp;gt; 0 || $(".player-narrowscreen").size() &amp;gt; 0;
        if(e.keyCode === 13){
            if(!wrapper.hasClass("ele-hide")){
                wrapper.toggleClass("ele-hide");
            } else if(isFullPage){
                wrapper.toggleClass("ele-hide");
                if(!wrapper.hasClass("ele-hide")){
                    input.focus();
                }
            }
            e.stopPropagation();
        }
    });

    let tooFast = false;
    let countInput = true;
    input.keyup(e=&amp;gt;{
        if(e.keyCode === 13){
            let text = input.val();
            if(text &amp;amp;&amp;amp; text.length &amp;gt; 0){
                if(!tooFast){
                    let sendTimeout = chat(text);
                    if(sendTimeout === 0){
                        wrapper.addClass("ele-hide");
                        $("#videoContainer").focus();
                        input.val("");
                        setInputCount(0);
                    } else {
                        tooFast = true;
                        $("#quick-chat-send-btn").toggleClass("div-disabled");
                        let disableTimer = setInterval(()=&amp;gt;{
                            if(sendTimeout &amp;gt; 0){
                                $("#quick-chat-send-btn").text(`倒计时:${sendTimeout}`);
                                sendTimeout--;
                            } else {
                                $("#quick-chat-send-btn").text("发送(enter)").toggleClass("div-disabled");
                                clearInterval(disableTimer);
                                tooFast = false;
                            }
                        }, 1000);
                    }
                }
            } else {
                wrapper.toggleClass("ele-hide");
                $("#videoContainer").focus();
            }
            e.stopPropagation();
        }
    }).on('compositionend', e =&amp;gt; {
        checkInputCount();
        setInputCount(input.val().length);
        countInput = true;
    }).on('input', e =&amp;gt; {
        if(countInput) {
            checkInputCount();
            setInputCount(input.val().length);
        }
    }).on('compositionstart', e =&amp;gt; {
        countInput = false;
    })

    let setInputCount = cnt =&amp;gt; $(".quick-chat-input-count").text(`${cnt}/30`);
    let checkInputCount = ()=&amp;gt;{
        let text = input.val();
        if(text.length &amp;gt;= 30) {
            input.val(text.substring(0, 30));
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I type some letters with Chinese input method, such as 'hhh' :&lt;/P&gt;&lt;P&gt;In chromium:&lt;/P&gt;&lt;P&gt;① When I type 'hhh', then p&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;ress the Enter key and release it immediately, it will input 'hhh' and don't send them. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;② When I type 'hhh', then press the Enter key &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;and hold&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt; for a while and then release it, it will input 'hhh' and send them. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;In Firefox:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;③ When I type 'hhh', then press the Enter key and release it immediately, it will input 'hhh' and send them. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Is this a Firefox bug?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Maybe the reason is there is monitor delays in chromium while Firefox not? &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Is there any settings in about:config to change ③ to ① ?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Expected behavior:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GIF 2024-5-20 20-37-16.gif" style="width: 614px;"&gt;&lt;img src="https://connect.mozilla.org/t5/image/serverpage/image-id/6375i6163BB1C90DD01B4/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="GIF 2024-5-20 20-37-16.gif" alt="GIF 2024-5-20 20-37-16.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Update：&lt;/P&gt;&lt;P&gt;Finally，I'm aware this is because Firefox &lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;responds to every keyup event independently, regardless of whether the keyup event is incidental to processing other tasks or not.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;such as this code：&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;input type="text" id="text"&amp;gt;
&amp;lt;script&amp;gt;
    document.getElementById("text").onkeyup = function(e) {
        alert("按键码: " + e.which + " 字符: " + String.fromCharCode(e.which));
    };
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Firefox, you cannot make this popup disappear by pressing the Enter key and releasing it immediately, while Chromium does allow it.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Misuzu_0-1716238267673.png" style="width: 400px;"&gt;&lt;img src="https://connect.mozilla.org/t5/image/serverpage/image-id/6379iC55A6B64246F0E17/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="Misuzu_0-1716238267673.png" alt="Misuzu_0-1716238267673.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;In this case, the keyup event of the Enter key is incidental to compositionend, but Firefox still executes the keyup function regardless of that, while Chromium behaves as expected.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2024 22:01:42 GMT</pubDate>
      <guid>https://connect.mozilla.org/t5/discussions/the-difference-between-firefox-and-chromium-about-keyup-event/m-p/57578#M20232</guid>
      <dc:creator>Misuzu</dc:creator>
      <dc:date>2024-05-20T22:01:42Z</dc:date>
    </item>
  </channel>
</rss>

