virtual-dom icon indicating copy to clipboard operation
virtual-dom copied to clipboard

`javascript:` ban disallows legitimate use for bookmarklets

Open Janiczek opened this issue 5 years ago • 4 comments

See https://github.com/Janiczek/ellies/issues/3

I want to create a bookmarklet, which means an <a href="javascript:...">link</a> that I can drag to my bookmarks tab and there click on it to perform some JS on any page I'm on.

Elm's VDOM disallows this so the best I could do is to link to a file on GitHub that contains the bookmark source code.

Janiczek avatar Feb 20 '20 21:02 Janiczek

It's still possible to have a javascript: link using Html.Attributes.property, although this seems like more of a workaround than a solution:

module Main exposing (main)

import Html exposing (Html, a, text)
import Html.Attributes exposing (property)
import Json.Encode as E


main : Html msg
main =
    a [ property "href" (E.string "javascript:alert(\"This works!\")") ] [ text "Click me" ]

Ellie link

jackwilsdon avatar Feb 21 '20 17:02 jackwilsdon

Note this workaround doesn't work with --optimize builds.

Janiczek avatar May 05 '22 16:05 Janiczek

Note this workaround doesn't work with --optimize builds.

Unfortunately this is true and makes this nice workaround useless :disappointed:

laurentpayot avatar May 06 '22 09:05 laurentpayot

virtual-dom has recently been fixed; this now doesn't work in non-optimized builds either.

Here is a way to have bookmarklets in Elm via WebComponents: https://ellie-app.com/hwbBHmqLQ8Ra1

Janiczek avatar May 16 '22 10:05 Janiczek