guardian / scribe

DEPRECATED: A rich text editor framework for the web platform
http://guardian.github.io/scribe/
Apache License 2.0
3.5k stars 245 forks source link

HTML pastes as plaintext in Firefox on Windows #103

Open thedanbob opened 10 years ago

thedanbob commented 10 years ago

There is a bug in Firefox on Windows (I believe this one) that causes pasted HTML to be identified as text/plain rather than text/html. That causes this check to fail and the content to be inserted as plaintext.

This appears to be an issue only with this particular combination of browser and OS. Firefox 28 on OS X 10.9.2 correctly identifies pasted HTML as text/html, while Firefox 28 on Windows 7 x86 does not. I don't have any other versions of Windows available to test on.

As a workaround, I added a useragent check to force Scribe to use the non-Clipboard API method of pasting when in Firefox on Windows. I'm sure there's a better way to do it :P

OliverJAsh commented 10 years ago

Nice find!

Have you got a link so I can take a look at your fork? Or, raise a PR and we can discuss it there? Obviously I would normally be against using the user-agent to determine support, but this sounds like a very special browser inconsistency, so maybe that’s the right thing to do in this case.

thedanbob commented 10 years ago

Here: https://github.com/danbob/scribe/commit/4e6ea748bc9d6bdf7434732f2e0dba12f64b01e6

Might be able to make it more specific than all Firefox and all Windows versions, but like I mentioned I can't test any other combinations.

OliverJAsh commented 10 years ago

Thanks for sharing that.

I would like to see a failing test for this before we merge the fix. Do you think you could have a go? We run the tests on Sauce Labs so we should be able to test it against various platforms and browser versions.

There are some steps for running the tests in the contributing docs.

thedanbob commented 10 years ago

Sure, I can give it a shot. Might take me a bit to figure it out.

OliverJAsh commented 10 years ago

@danbob Let me know if you get stuck at any point, I will try to respond on here and via IRC (Freenode) under OliverJAsh ASAP. It shouldn’t be too difficult :smile:

OliverJAsh commented 10 years ago

@danbob Just added some docs that will help https://github.com/guardian/scribe/blob/oja-sauce-connect/CONTRIBUTING.md#testing-via-sauce-labs

OliverJAsh commented 10 years ago

New link: https://github.com/guardian/scribe/blob/master/CONTRIBUTING.md#testing-via-sauce-labs

thedanbob commented 10 years ago

Well, this is trickier than I thought it would be. It seems that HTML copied from within Firefox is identified correctly as text/html. It's only when you copy from an external source (e.g. Chrome, Microsoft Word) that it fails. I have no idea how to test that :confused:

OliverJAsh commented 10 years ago

@danbob In that case, is this still a Firefox bug? I thought the MIME type was set by the application you copied from? I don’t really know how any of this works, but it would be good to know more.

Firefox 28 on OS X 10.9.2 correctly identifies pasted HTML as text/html, while Firefox 28 on Windows 7 x86 does not.

Have you tried pasting with Chrome on Windows 7 (x86)?

thedanbob commented 10 years ago

I thought the MIME type was set by the application you copied from?

@OliverJAsh I thought so too, but I guess not... or maybe Firefox is just ignoring it. If I copy HTML from Firefox or Word and paste into Chrome, it behaves as expected. If I copy from anything besides Firefox and paste into Firefox, I hit the bug. (All on Windows 7 x86, of course.)

thedanbob commented 10 years ago

@OliverJAsh here's some technical details I found while debugging: on paste, the event contains a ClipboardEvent object which has a types method. In Chrome, types is just an array i.e. ["text/html","text/plain"]. In Firefox, it's a DOMStringList that acts like an array (you can do types[0]).

Also, it looks like the bug extends beyond Windows. When copying RTF text from TextEdit on OS X, Chrome identifies it as ["text/plain","text/html","text/rtf"] but Firefox only gives ["text/plain"]. When copying the same content from Word on OS X, Chrome gives the same MIME types and Firefox reports ["text/html","text/plain"].

My best guess is that either Firefox doesn't correctly interpret the MIME types set by some applications, or they aren't set by the applications properly and Chrome just does a better job of figuring them out.

OliverJAsh commented 10 years ago

Any updates on this? Is it a big issue for you?

OliverJAsh commented 10 years ago

What’s the status of Firefox 29?

thedanbob commented 10 years ago

Firefox 29 is the same. It's not a big issue, the user agent check does the trick for me and I can easily apply it manually for new scribe releases. Also, it looks like the bug is finally getting some attention from the Firefox devs, so hopefully it won't be a problem for much longer.

TooTallNate commented 10 years ago

FWIW OS X Firefox has the same issue. Rich text cannot be pasted.

OliverJAsh commented 10 years ago

@TooTallNate I’m not seeing that?! That would be a pretty big bug…