Code: [Select] function not working in recent web browsers

Started by PCNetSpec, April 23, 2017, 08:46:41 AM

Previous topic - Next topic

PCNetSpec

The "Code: [Select]" function in SMF 2 has for as long as I can remember always displayed "javascript:void(0);" at the bottom left of screen in Firefox/Chromium/Chrome (and probably others) but the function still worked .. ie. when you clicked on "Select" all the text in the code box got selected.

Now it does not, you still get the "javascript:void(0);" message, but clicking "Select" does nothing .. the text in the code box does not get selected.

This seems to be related to web browser version, as if I drop back to Firefox 51 the function works, but it does not work in Firefox 53.

[SMF 2.0.13]
(and this forum .. 2.0.14)
test here

Arantor


PCNetSpec

It does yes .. but as I said the function works in Firefox 51 and earlier versions of Chromium/Chrome. It just seems to be in recent browsers.

Here's an example:
https://forum.peppermintos.com/index.php/topic,5420.msg54342.html#msg54342

Arantor

I was half expecting you to say no. Firefox has been changing its requirements so that higher or more sensitive features require HTTPS and potentially that would have been one of them. But it's not that.

Hmm, it still works on Chrome 57, and in Firefox 52, but you're right it's broken in FF 53. I wonder what they changed that broke.

PCNetSpec

You're also right, it's working here too in Chromium 57 .. so it appears to be just Firefox 53 where it's broken ???

Illori

console says
QuoteIndexSizeError: Index or size is negative or greater than the allowed amount script.js?fnl (line 1366)
// Firefox at el.
else if (window.getSelection)
{
var oCurSelection = window.getSelection();
// Safari is special!
if (oCurSelection.setBaseAndExtent)
{
var oLastChild = oCodeArea.lastChild;
oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length);
}
else
{
var curRange = document.createRange();
curRange.selectNodeContents(oCodeArea);

oCurSelection.removeAllRanges();
oCurSelection.addRange(curRange);
}
}


1366 is oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length);

i wonder if we no longer need the code just for firefox.

Arantor

Would need to be tested against Safari (incl. Mobile Safari) as well if it were changed, as well as older Firefox.

Illori

interesting that code is the same in SMF 2.1 but it does not have this issue.

fugenkomponist

#8
Quote from: Illori on April 23, 2017, 10:56:49 AM
1366 is oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length);
If you replace 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length by 1 you'll see that Firefox selects the first line and Chromium more but not always the whole text (I assume something like "until the first closing double quote"). So it seems like this expression gives a node index out of range and different browsers count differently ...

As a workaround you can switch back to the old behaviour for Firefox:// Safari is special!
if (oCurSelection.setBaseAndExtent && !is_ff)
{
setBaseAndExtent is supported in Firefox 53 (see release notes at hxxp:developer.mozilla.org/en-US/Firefox/Releases/53 [nonactive]) so I think this is why the behaviour changed in this version.

PCNetSpec

Code:[Select] now appears to be broken in Chrome/Chromium 58 too .. at least on SMF 2.0.13 (but not here on 2.0.14 ???)

Test URL
https://forum.peppermintos.com/index.php/topic,5485.msg54966.html#msg54966

Chromium 58.0.3029.81 console reads
Uncaught DOMException: Failed to execute 'setBaseAndExtent' on 'Selection': There is no child at offset 183.
    at smfSelectText (eval at <anonymous> (https://forum.peppermintos.com/index.php/topic,5485.msg54966.html:1:1), <anonymous>:47:407)
    at HTMLAnchorElement.onclick (https://forum.peppermintos.com/index.php/topic,5485.msg54966.html#msg54966:386:485)


Chrome 58.0.3029.96 is indicating the problem lies at the line highlighted in red below
Quote// Firefox at el.
   else if (window.getSelection)
   {
      var oCurSelection = window.getSelection();
      // Safari is special!
      if (oCurSelection.setBaseAndExtent)
      {
         var oLastChild = oCodeArea.lastChild;
         oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length);
      }
      else
      {
         var curRange = document.createRange();
         curRange.selectNodeContents(oCodeArea);

         oCurSelection.removeAllRanges();
         oCurSelection.addRange(curRange);
      }
   }

For clarity, this is WITHOUT fugenkomponist's workaround .. which I only just spotted, and haven't tried yet as I'm assuming it's a Firefox specific workaround (?) but the problem now isn't.

Gluz

I've seen this, and after looking through the code I see that this part:

// Safari is special!
if (oCurSelection.setBaseAndExtent)
{
var oLastChild = oCodeArea.lastChild;
oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length);
}


Is intended for Safari, but since Firefox 52 they added this:"setBaseAndExtent"

I tested something by adding is_safari to that if, similar to the change fugenkomponist did but to check only for Safari instead filter out only Firefox, since that part is intended for Safari. That makes it work in Firefox 53 and Chrome 58 as intended.

The code looks like this:
// Safari is special!
if (oCurSelection.setBaseAndExtent && is_safari)
{
var oLastChild = oCodeArea.lastChild;
oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length);
}


Those browsers are adding support for setBaseAndExtent but is broken, and all software that uses that is getting this errors.

Linkjay

I play games in my free time and volunteer my knowledge and support to the gaming communities of the internet.

You can contact me by these methods:
Use my Contact Script • PM me here • Add me on Steam

tfs

Has there been any change on this issue? I'm using SMF 2.14 and FF 54.0.1 (32-bit), and the select option is not working. It works in IE. My site is using HTTPS exclusively.
A good tree cannot bring forth evil fruit, neither can an evil tree bring forth good fruit.

FragaCampos

I'm using FF 54.0.1 (32-bit) and SMF 2.0.13 and the select option doesn't work either.

tfs

Looks like it's also broken on my iPhone with Safari.
A good tree cannot bring forth evil fruit, neither can an evil tree bring forth good fruit.

GravuTrad

Quote from: FragaCampos on July 11, 2017, 05:51:57 PM
I'm using FF 54.0.1 (32-bit) and SMF 2.0.13 and the select option doesn't work either.

Same thing
On a toujours besoin d'un plus petit que soi! (Petit!Petit!)


Think about Search function before posting.
Pensez à la fonction Recherche avant de poster.

PCNetSpec

#16
Any movement on this issue ?

It seems to be broken in both Firefox 55 and Chromium 60 .. although it is still working in Chrome 58 on this forum (SMF 2.0.14), but not on my forum (SMF 2.0.13) :-\

tfs

Still broken on Firefox Quantum 57.0 (x64)

I miss this feature!
A good tree cannot bring forth evil fruit, neither can an evil tree bring forth good fruit.

Krawieco

Quote from: tfs on November 15, 2017, 11:10:57 AM
Still broken on Firefox Quantum 57.0 (x64)

I miss this feature!

Hey tfs, did you get it working yet? Because I haven't been able to.  :-[

butch2k

Quote from: PCNetSpec on April 23, 2017, 08:46:41 AM
The "Code: [Select]" function in SMF 2 has for as long as I can remember always displayed "javascript:void(0);" at the bottom left of screen in Firefox/Chromium/Chrome (and probably others) but the function still worked .. ie. when you clicked on "Select" all the text in the code box got selected.

Now it does not, you still get the "javascript:void(0);" message, but clicking "Select" does nothing .. the text in the code box does not get selected.

This seems to be related to web browser version, as if I drop back to Firefox 51 the function works, but it does not work in Firefox 53.

[SMF 2.0.13]
(and this forum .. 2.0.14)
test here
I do not use the same code anymore but i encountered a similar issue with mine.
IIRC you should not use textContent.length which is the content length measured in characters BUT the number of text lines (number of nodes). It used to work even if the number used was superior but not anymore, you should use a number <= to the number of lines in the text being selected.

Try this
oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, oCodeArea.childElementCount);

instead of

oCurSelection.setBaseAndExtent(oCodeArea, 0, oLastChild, 'innerText' in oLastChild ? oLastChild.innerText.length : oLastChild.textContent.length);

Let me know if it works as i'm unable to test it right now.

Advertisement: