Is it possible to create an element if you have its constructor but don't know its tag name?
Example:
class CustomElement extends HTMLElement {}
customElements.define(genRandomString(), CustomElement);
Is it possible to create a new instance of CustomElement? Or can you obtain its tag name in any way?
I'm asking this because I'm not sure what's the correct way to pass custom elements to functions that need them: do I need to pass around both the name and the constructor, in case one may need to either create an element (which requires the name) or to check whether an existing element is of this kind (which requires the constructor)?
Is this what you are asking for:
let foo = "bar";
window[ genRandomString() ] = foo;
And then you want to know what getRandomString produced?
Only when you monitor window can you capture what is added to it.
Same with WebComponents, only when you hook into customElements.define can you record what names are used.
In other words: mess with its prototype and potentially breaking its default execution.
But this only works from the moment you are in control; you could have missed all Web Components created already, at that time.
Can you explain WHY you want to do this?
Is it possible to create an element if you have its constructor but don't know its tag name?
If you have access to the constructor (like you said you have), you can just use
const instance = new CustomElement();
Please note that this might fail if the constructor doesn't conform to Custom Element constructor constraints.