
Bookmarklets in Internet Explorer 11: storage format, limits and unspoken rules, insidious bug
After two bookmarklets running on Google Chrome and Firefox immediately refused to work in Internet Explorer 11, and they did not display any error messages to the console and did not show any signs of life at all, I began to understand what was going on.
At first I decided that it was a limit on the length of the URL, and thus on the length of the bookmarklet. In IE 7, the limit was 2083 characters; in IE 11, as experimenters assured, the limit was increased. It was necessary to find out empirically what this border is now.
But first, a small introduction.
Google Chrome stores bookmarks in JSON, Firefox - in the sqlite database. Therefore, the names of the bookmarks can be arbitrary. IE stores each bookmark as a separate file, for example, in the% userprofile% \ Favorites \ Links folder. Therefore, the browser will adjust the names of the bookmarks so that they fit the norms of the file system (replace question marks, for example). Therefore, in IE, there cannot be two bookmarks in the same folder with the same name, but in Google Chrome and Firefox they can (bookmarks in them can even be without a name at all, only with a site icon or standard substitute).
Google Chrome and Firefox allow you to create a bookmark from scratch by entering the name and URL in the appropriate fields, including the bookmarklet code. At the same time, Google Chrome and Firefox remove line breaks in the code, and do different things with whitespace: the first partially removes them, and partially leaves them, as far as the syntax allows; the second turns whitespace into the% 20 character, as the encodeURI () and encodeURIComponent () functions do. After creation, both browsers allow you to edit both ordinary bookmarks and bookmarklets.
In IE, you can add a bookmarklet only by dragging a link to the Favorites panel. Editing the code after creating a bookmark in the browser itself is no longer possible (it cannot even be viewed in the browser: only the beginning is visible in the tooltip, and calling the bookmark properties opens a window in which there is no field for URL or code). But there is a workaround: you can edit bookmark files in the mentioned folder.
These files have the extension .url, and are identical in format to the text files in the .ini configuration. Here is an example of a simple bookmarklet saved to a file for IE 11.
This blank can be used as a template: if you replace both lines of code in it and save it with a valid file name in the mentioned folder, a new bookmarklet will appear in the Favorites panel. In doing so, you need to take into account this feature: IE reads bookmarks once during the opening of a window or tab. If you edit the file, the window or tab will still operate on the old version. If you close the window and open it again or open a new tab, then the file changes will take effect for them. Therefore, there may be such a situation that clicking on the same bookmark in five different tabs can produce five different results if you edited the file before each tab was opened. The confusion is aggravated by the fact that IE saves running processes: you can close the tab, IE will leave the child process in memory and use it when you open another tab, and the legacy of read bookmarks will go back to this, not quite new, tab. Therefore, when testing the code of bookmarklets and directly editing their files, either restart one window, or open new tabs without closing the previous ones (it will probably be easier to use the console).
Now about the file format, or rather about the part that interests us. As we can see, the URL or bookmarklet code is stored in two duplicate keys. But between them there is both a difference and a relationship. The following rules were found out experimentally:
1. Key limit
2. With a bookmarklet code of more than 2083 characters, IE breaks the key value
3. With a bookmarklet code of more than 5119 characters, IE leaves
4. With a large code, the first 2083 characters of both keys must match before the character . If they differ by at least one character or if the first key is at least 2082 characters, the bookmarklet will not work.
Having clarified these norms, I checked my non-working bookmarklets for compliance. There were no violations. They were more than three thousand characters in length; all the format rules in the files were followed.
Apparently, I’ll have to check with different options and the size of the code, maybe there are still hidden rules, I thought. Or there are uncatchable errors, and you need to instruct
And then I noticed that both files have a strange similarity in one strange detail. In both, the URL key value ended with a space. I was even earlier surprised why this IE inserted a space at the end of the line. But, having looked closely, I realized that IE did not insert anything. By a funny coincidence, both codes of my bookmarklets had a space on 2083 characters. And it dawned on me how terrible, so saving the conjecture, which was immediately justified by tests. I had to formulate one more bookmarklet rule for IE 11, which is actually a bug rather than a rule:
5. If the code bookmarklet in place in 2083 will be the symbol blank , and thus, the gap will be the last key symbol
From all this, at least two tips for creating bookmarklets for IE 11 follow:
- Check the character limit of 5119 characters.
- Check the absence of a space on 2083 characters, or clear the spaces to the maximum, or encode javascript: URL using functions, or paste it from Firefox bookmarks.
Finally, I will give an example of an .url file with a threshold key size, for those who want to check the described:
This is the working bookmarklet code. It will stop working if you:
- increase by at least one of the keys or both keys (even by the same character);
- reduce the first key by at least one character;
- replace at least one character in one of the keys without changing identically the same character in another key;
- replace 2083 characters in both keys with a space (in the first key, this is the last character, in the second key, one of the characters in the middle of the line).
It was written in the hope of preserving someone's time and health.
If someone knows the site where it makes sense to send a message about this dubious behavior (like bugzilla.mozilla.org for Firefox or code.google.com/p/chromium/issues/listfor Google Chrome), please inform. Thanks for attention.
At first I decided that it was a limit on the length of the URL, and thus on the length of the bookmarklet. In IE 7, the limit was 2083 characters; in IE 11, as experimenters assured, the limit was increased. It was necessary to find out empirically what this border is now.
But first, a small introduction.
Google Chrome stores bookmarks in JSON, Firefox - in the sqlite database. Therefore, the names of the bookmarks can be arbitrary. IE stores each bookmark as a separate file, for example, in the% userprofile% \ Favorites \ Links folder. Therefore, the browser will adjust the names of the bookmarks so that they fit the norms of the file system (replace question marks, for example). Therefore, in IE, there cannot be two bookmarks in the same folder with the same name, but in Google Chrome and Firefox they can (bookmarks in them can even be without a name at all, only with a site icon or standard substitute).
Google Chrome and Firefox allow you to create a bookmark from scratch by entering the name and URL in the appropriate fields, including the bookmarklet code. At the same time, Google Chrome and Firefox remove line breaks in the code, and do different things with whitespace: the first partially removes them, and partially leaves them, as far as the syntax allows; the second turns whitespace into the% 20 character, as the encodeURI () and encodeURIComponent () functions do. After creation, both browsers allow you to edit both ordinary bookmarks and bookmarklets.
In IE, you can add a bookmarklet only by dragging a link to the Favorites panel. Editing the code after creating a bookmark in the browser itself is no longer possible (it cannot even be viewed in the browser: only the beginning is visible in the tooltip, and calling the bookmark properties opens a window in which there is no field for URL or code). But there is a workaround: you can edit bookmark files in the mentioned folder.
These files have the extension .url, and are identical in format to the text files in the .ini configuration. Here is an example of a simple bookmarklet saved to a 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 blank can be used as a template: if you replace both lines of code in it and save it with a valid file name in the mentioned folder, a new bookmarklet will appear in the Favorites panel. In doing so, you need to take into account this feature: IE reads bookmarks once during the opening of a window or tab. If you edit the file, the window or tab will still operate on the old version. If you close the window and open it again or open a new tab, then the file changes will take effect for them. Therefore, there may be such a situation that clicking on the same bookmark in five different tabs can produce five different results if you edited the file before each tab was opened. The confusion is aggravated by the fact that IE saves running processes: you can close the tab, IE will leave the child process in memory and use it when you open another tab, and the legacy of read bookmarks will go back to this, not quite new, tab. Therefore, when testing the code of bookmarklets and directly editing their files, either restart one window, or open new tabs without closing the previous ones (it will probably be easier to use the console).
Now about the file format, or rather about the part that interests us. As we can see, the URL or bookmarklet code is stored in two duplicate keys. But between them there is both a difference and a relationship. The following rules were found out experimentally:
1. Key limit
URL
= 2083 characters. Key Limit ExtendedURL
= 5119 characters. 2. With a bookmarklet code of more than 2083 characters, IE breaks the key value
URL
exactly at 2083 characters , mechanically cutting off everything else. He obviously takes the working code only from the second key. 3. With a bookmarklet code of more than 5119 characters, IE leaves
URL
2083 characters in the key , and leaves the entire code in the keyExtendedURL
. When you add a bookmark to Favorites no warning to the user is not submitted , then the bookmarklet just does not work, if unsuccessful launches of any error messages to the console also is not . 4. With a large code, the first 2083 characters of both keys must match before the character . If they differ by at least one character or if the first key is at least 2082 characters, the bookmarklet will not work.
Having clarified these norms, I checked my non-working bookmarklets for compliance. There were no violations. They were more than three thousand characters in length; all the format rules in the files were followed.
Apparently, I’ll have to check with different options and the size of the code, maybe there are still hidden rules, I thought. Or there are uncatchable errors, and you need to instruct
try-catch
. In general, prepare for an unpredictable number of tests. And then I noticed that both files have a strange similarity in one strange detail. In both, the URL key value ended with a space. I was even earlier surprised why this IE inserted a space at the end of the line. But, having looked closely, I realized that IE did not insert anything. By a funny coincidence, both codes of my bookmarklets had a space on 2083 characters. And it dawned on me how terrible, so saving the conjecture, which was immediately justified by tests. I had to formulate one more bookmarklet rule for IE 11, which is actually a bug rather than a rule:
5. If the code bookmarklet in place in 2083 will be the symbol blank , and thus, the gap will be the last key symbol
URL
, a bookmarklet will not work. As with the listed violations of the rules, the user will not receive any preliminary warnings or subsequent error messages. From all this, at least two tips for creating bookmarklets for IE 11 follow:
- Check the character limit of 5119 characters.
- Check the absence of a space on 2083 characters, or clear the spaces to the maximum, or encode javascript: URL using functions, or paste it from Firefox bookmarks.
Finally, I will give an example of an .url file with a threshold key size, for those who 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 123456789123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 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 123456789123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1244589}) ()}) ()}) ()}) ()}) ()}) ()}) ()}) ()}) ()}) ()
This is the working bookmarklet code. It will stop working if you:
- increase by at least one of the keys or both keys (even by the same character);
- reduce the first key by at least one character;
- replace at least one character in one of the keys without changing identically the same character in another key;
- replace 2083 characters in both keys with a space (in the first key, this is the last character, in the second key, one of the characters in the middle of the line).
It was written in the hope of preserving someone's time and health.
If someone knows the site where it makes sense to send a message about this dubious behavior (like bugzilla.mozilla.org for Firefox or code.google.com/p/chromium/issues/listfor Google Chrome), please inform. Thanks for attention.