The 'target' parameter in emscripten_* functions is confusing.

35 views
Skip to first unread message

Floh

unread,
Oct 27, 2020, 1:36:32 PM10/27/20
to emscripten-discuss
I just realized that I massively misunderstood the target parameter in functions like emscripten_webgl_create_context() (e.g. see documentation here: https://emscripten.org/docs/api_reference/html5.h.html#c.emscripten_webgl_create_context), and that all my code only worked by accident because I used the string "canvas" as target name (which doesn't work with more than one WebGL canvas on a page).

This target parameter isn't the element **id**, but a **CSS selector** (https://www.w3schools.com/cssref/css_selectors.asp)

I seem to remember that there was a documentation about the convention used in those target strings (e.g. what '#' actually means), and I could've sworn that the form "#canvas" was some outdated emscripten-specific special-case-name and that the "new way" to name the target element would be "canvas" instead, but I can't find this anymore no matter how much Google-fu I'm trying to conjure.

IMHO the whole thing would be a lot less confusing if this parameter wouldn't be called 'target' but 'selector' or even 'css_selector' at least in the documentation. That says immediately what this string means for webby people, and for non-webby people it's easy to google.

Just my 2ct :)
-Floh.

Brion Vibber

unread,
Oct 27, 2020, 2:17:12 PM10/27/20
to emscripten Mailing List
Even if the name 'target' is kept, the documentation for the parameter should definitely be changed to indicate it's a CSS selector -- the current wording is very unclear.

-- brion

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/bbf7a80b-733d-4430-b68b-c63a7044372ao%40googlegroups.com.

Jukka Jylänki

unread,
Nov 10, 2020, 8:30:00 AM11/10/20
to emscripte...@googlegroups.com
Yeah, changing the parameter name from "target" to "targetSelector" or
"cssSelector" sounds good.

The behavior is something that changed a year or two ago,
querySelector being a more flexible way to identify a target element.
It used to denote an element ID. There was a deprecation period, an
option to flip between the two conventions, etc. and at some point the
migration was completed. You can still get to the old behavior with
Emscripten linker flag -s
DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0.
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAFnWYTn4UKFwHgYVJQ3jFc%2B7kZCkmS2GCyfUzfYjuRVHDm6doA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages