bookmarkleter icon indicating copy to clipboard operation
bookmarkleter copied to clipboard

Anonymizing function doesn't work with prompt()

Open BGG-Tools opened this issue 7 years ago • 3 comments

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)})();

BGG-Tools avatar Jun 11 '17 14:06 BGG-Tools

Hmm, thanks. Thought I had addressed this in #3. Will take a look.

chriszarate avatar Jun 11 '17 16:06 chriszarate

P.S.: I haven't checked against your code base, I was just using the page http://chriszarate.github.io/bookmarkleter/

BGG-Tools avatar Jun 11 '17 16:06 BGG-Tools

I've had the same issue when using the page http://chriszarate.github.io/bookmarkleter/, and trying to use the fetch API.

lily-mara avatar Sep 08 '17 14:09 lily-mara

This was fixed long ago. Thanks for the report. :)

chriszarate avatar Mar 03 '23 05:03 chriszarate