Developers Club geek daily blog

2 years, 3 months ago
After at once two bukmarklet working in Google Chrome and Firefox have refused to work in Internet Explorer 11, and did not give in the console any error messages and did not give life signs at all, I began to understand, in what business.

At first I have decided that matter in limit at URL length and by that at length of bukmarklet. In IE 7 restriction was in 2083 the character, in IE 11, on assurances of the experimenting users, limit have increased. It was necessary to find out by practical consideration, what this border now.

But at first small preface.

Google Chrome stores tabs in JSON, Firefox — in the sqlite database. Therefore tabs can have any names. IE stores each tab as the separate file, for example, in the %userprofile %\Favorites\Links folder. Therefore the browser will adjust names of tabs that they approached under norms of file system (to replace question marks, for example). Therefore in IE there cannot be in one folder two tabs with identical name, and in Google Chrome and Firefox — can (tabs in them can be even in general without name, only with icon of the site or standard substitute).

Google Chrome and Firefox allow to create tab from scratch, entering into the corresponding fields the name and URL, including code of bukmarklet. At this Google Chrome and Firefox delete line feeds in code, and with whitespace characters arrive differently: the first partially deletes them, and partially leaves as far as syntax allows; the second turns whitespace characters into sign %20 as it is done by the encodeURI functions () and encodeURIComponent (). After creation both browsers allow to edit both normal tabs, and bukmarkleta.

To add to IE bukmarklt it is possible only by drag and drop of the link to Favorites panel. It is impossible to edit code after creation of tab in the browser already (it even cannot be looked in the browser: in the tooltip balloon only the beginning is visible, and the call of properties of tab opens window in which there is no field for URL or code). But there is alternate path: it is possible to edit files of tabs in the mentioned folder.

These files have the .url expansion, and on format are identical to text files of configuration of .ini. Here example of the simple bukmarklet saved in the file for IE 11.

[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,15
[InternetShortcut]
URL=javascript:(function(){alert('Hello, world!');})()
IDList=
[Bookmarklet]
ExtendedURL=javascript:(function(){alert('Hello, world!');})()


This preparation can be used as template: if to replace in it both code lines and to save with admissible file name in the mentioned folder, on panel of Favorites there will be new bukmarklt. Thus it is necessary to consider such feature: IE reads out tabs once during opening of window or tab. If you edit the file, the window or tab will operate all the same with the old version. If you close window and it will reopen or will open new tab, then changes of the file will become effective for them. Therefore there can be such situation that clicking the same tab in five different tabs can give out five different results if before each opening of tab you edited the file. The confusion is aggravated by that circumstance that IE saves the started processes: you can close tab, IE will leave child process in memory and uses it when opening other tab, and the heritage of read tabs will depart to this, not absolutely new tab any more. Therefore when testing code of bukmarklet and direct editing their files or restart one window, or open new tabs, without closing previous (probably, it will be simpler to use the console).

Now about the file format, is more correct about interesting us speak rapidly. As we see, URL or code of bukmarklet is stored in two keys duplicates. But between them is both distinction, and interrelation. Experimentally it was succeeded to find out the following rules:

1. Key limit URL = 2083 signs. Key limit ExtendedURL = 5119 signs.
2. At code of bukmarklet more than in 2083 the sign IE tears off value of key URL precisely on 2083 sign, cutting mechanically everything remained. Working code it, obviously, takes only from the second key.
3. At code of bukmarklet more than in 5119 signs IE leaves in key URL 2083 signs, and in key ExtendedURL leaves all code. When adding such tab in Favorites of any warnings to the user it is not issued, bukmarklt then simply does not work, at unsuccessful starts no error messages in the console too are present.
4. At big code the first 2083 signs of both keys have to match to the character. If they differ at least in one sign or if the first key is at least 2082 signs, bukmarklt will not work.

Having found out these norms, I have checked the idle bukmarkleta for compliance. No violations existed. There were they on three thousand characters with superfluous, all rules of format in files have been followed.

It is visible, it is necessary to check with different options and code size, maybe, there are still hidden rules, I have thought. Or there are not caught errors, and it is necessary navstavlyat try-catch. Generally, to prepare for unpredictable number of tests.

And here I have noticed that both files have strange similarity in one strange part. In both value of key of URL came to an end on space. I was surprised even earlier, why it is IE have inserted space in line end. But, having looked narrowly, has understood that IE did not insert anything. On amusing combination of circumstances both codes of my bukmarklet had space on 2083 character. And has dawned on me as terrible, so and saving guess which has right there come true tests. It was necessary to formulate one more rule of bukmarklet for IE 11 which actually it is rather bug, than the rule:

5. If in code of bukmarklet on site 2083 characters appear space and, thereby, the space will be the last character of key URL, such bukmarklt will not work. As well as at the listed violations of the rules, neither the user will not receive preliminary warnings, nor the subsequent error messages.

At least two councils creating bukmarkleta for IE 11 follow from all this:

— Check limit of characters in 5119 signs.
— Check lack of space on 2083 character, or clean spaces to the maximum, or code javascript: URL by means of functions, or insert it from the FireFox tabs.

Finally I will give .url file example with threshold size of keys, for those who will want to check the described:

test.url
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,15
[InternetShortcut]
URL=javascript:(function(){alert('123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123
IDList=
[Bookmarklet]
ExtendedURL=javascript:(function(){alert('123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 12');})()


It is code of working bukmarklet. It will cease to work, if you:

— will increase at least by sign one of keys or both keys (even on the same sign);
— reduce the first key at least by one sign;
— replace at least one sign in one of keys, without having changed identically the same sign in other key;
— to the place of 2083 characters in both keys will put space (in the first key it is the last character, in the second key — one of characters in the middle of the line).

It is written in hope to save to someone time and health.

If someone knows the site where there is sense to direct the message on this doubtful behavior (like bugzilla.mozilla.org for Firefox or code.google.com/p/chromium/issues/list for Google Chrome), report, please. Thanks for attention.

This article is a translation of the original post at habrahabr.ru/post/263443/
If you have any questions regarding the material covered in the article above, please, contact the original author of the post.
If you have any complaints about this article or you want this article to be deleted, please, drop an email here: sysmagazine.com@gmail.com.

We believe that the knowledge, which is available at the most popular Russian IT blog habrahabr.ru, should be accessed by everyone, even though it is poorly translated.
Shared knowledge makes the world better.
Best wishes.

comments powered by Disqus