This should not be necessary. It sounds to me like there is an underlying gecko bug that should be reported and investigated.

We might want to land this code as a workaround to that bug if it doesn't look like it will be fixed quickly, but we shouldn't just fix it here without reporting the larger bug.

So file a gecko bug and add a comment saying that this is a workaround, and include the bug number of the bug you filed.

Also, I don't see any reason to use a data attribute here instead of a global variable. We're never going to have more than one of them at a time.