YouTube focus fix script update

A new release of the Tampermonkey/Greasemonkey script "YouTube focus fix" is available: Version 0.4.

You can get it here. For more details on the features of this script, please visit the Creations page.

It fixes a problem that prevented the script from working in the latest Chrome versions. No new features are present. It is recommended to update to the new version of the script to ensure that it keeps working properly.

A few days ago, I noticed that the script is no longer working in Chrome, but it still works in Firefox. I debugged the problem and found out the following things:

  • YouTube indicates a valueless tabindex on its movie player.
  • A valueless tabindex has the value of an empty string "".
  • The HTML5.1 standard mandates that "The tabindex attribute, if specified, must have a value that is a valid integer". In this case, the tabindex attribute is specified but with an empty value.
  • The HTML5.1 standard goes on to define what happens when this requirement is violated or the tabindex is omitted. Unfortunately, these definitions are just suggestions and worst of all, they are contradictory. As a C++ programmer, I'd call this description "vaguely defined behaviour" (a cousin of the notorious and dreaded "undefined behaviour"). Vaguely defined behaviour sums up the behaviour of HTML, CSS and JavaScript pretty well in general.
  • A new update in Chrome seems to have changed the browser's vaguely defined behaviour.
  • Due to this issue, I am forced to handle this special case in my script and accommodate all the vaguely behaving browsers with a workaround.
  • The workaround is to define a special focus function that first sets the tabindex to a valid number, calls focus() and then resets the tabindex to whatever it was before.
  • The web hasn't changed all that much since its early years after all. It is a pipe dream to think that if your code works in one browser, it works in all of them. It is probably a pipe dream to think that your code works, period.

Post comment

CAPTCHA
* required field

Comments

(no comments yet)