bookmarkleter
bookmarkleter copied to clipboard
Anonymizing function doesn't work with prompt()
The anonymizing function doesn't play nice with internal Javascript functions like "prompt". After the code completes, the window is then evaluated/replaced to just show the string "true". Minimal test case:
val = prompt("What's your name?"); if (val) alert("Hello, "+val);
Which is being converted to the following code:
javascript:!function(){val=prompt("What's%20your%20name?"),val&&alert("Hello,%20"+val)}();
In my browser (Firefox 53.0.3 64-Bit), the window's contents change to "true" after the code completes.
The code with the following anonymizing function works as intended:
javascript:(function(){val=prompt("What's%20your%20name?"),val&&alert("Hello,%20"+val)})();
From my understanding, the highlighted issue is, that the output of the anonymizing function is being inverted and can evaluate to "true". Maybe an even better way would be to generally cast it to void:
javascript:void(function(){val=prompt("What's%20your%20name?"),val&&alert("Hello,%20"+val)})();
Hmm, thanks. Thought I had addressed this in #3. Will take a look.
P.S.: I haven't checked against your code base, I was just using the page http://chriszarate.github.io/bookmarkleter/
I've had the same issue when using the page http://chriszarate.github.io/bookmarkleter/, and trying to use the fetch
API.
This was fixed long ago. Thanks for the report. :)