This redditor found an interesting Chrome UX behavior on paste. Chrome squashes spaces when pasted into the address bar or in window.prompt. But does not squash when pasting into input fields or in the console.

Here is a runnable snippet with sample inputs and outputs.

On Chrome:

                 input | typed    | copy/pasted
 "h e l l o w o r l d" | 9 spaces | 9 spaces
 "hello         world" | 9 spaces | 1 spaces

On Firefox:

                 input | typed    | copy/pasted
 "h e l l o w o r l d" | 9 spaces | 9 spaces
 "hello         world" | 9 spaces | 9 spaces

var str = window.prompt('Enter a few spaces.');
var spaces = (str.match(/ /g) || []).length;
console.log(`You entered ${spaces} spaces`);

Is this behavior documented anywhere in Chrome? I can't find this through a cursory search. Should this be considered a Chrome bug? On one hand, it could be nice to hand-hold certain users, but on the other hand, Chrome is not respecting the users' explicit instructions.

Is there a way to prevent this behavior or work around?

More findings, on Chrome 65 on Linux:

Using the X selection copy buffer thing (select, middle-click), the spaces are preserved when pasting into a window.prompt input. But, the spaces are not preserved when pasting into the address bar.

Using ctrl+c, ctrl+v, spaces are not preserved in either window.prompt nor the address bar.

Commentors report that this behavior is not present in OSX.

  • Using your window.prompt() example, it seems to respect the amount of spaces I type. My User-Agent string is Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 if that matters to anyone. Apr 11, 2018 at 5:01
  • 1
    So you mean when you paste hello world, you have You entered 1 spaces in the console? I do have You entered 9 spaces on chrome65 macOs flavor. Ah funny SO's comment text wrapping rules...
    – Kaiido
    Apr 11, 2018 at 5:02
  • I'm on Chrome 65 on Linux Mint and get "1 spaces" on the input "1 9spaces". (Stackoverflow also seems to squash that... I have nine spaces there)
    – 000
    Apr 11, 2018 at 5:03
  • Using ctrl+c/ctrl+v on Linux Mint Chrome, the spaces are squashed on paste. Using the X copy buffer (select, middle-click), the spaces are respected! What?!
    – 000
    Apr 11, 2018 at 5:06
  • 1
    @JoeFrambach it seems the behavior is exclusive to particular OS builds of Chrome, based on what's been discussed. I have also never heard of vendors "documenting UX behavior." Since there is no strict requirement for consistent behavior of UX, other than mild annoyance on users' behalf, and since this is not directly related to programming, I fail to see how this is considered on-topic here. Apr 11, 2018 at 5:12


You must log in to answer this question.

Browse other questions tagged .