Check if the CSS is already injected or not

64 views
Skip to first unread message

Zeeshan

unread,
Nov 21, 2022, 2:43:26 AM11/21/22
to Blockly
Hi all,

I want to check if the CSS I want to inject is previously injected or not, is there any way we can check it?
When I try to register some of my own CSS I am getting an error it is already injected.

Thanks
Zeeshan

Neil Fraser

unread,
Nov 21, 2022, 4:05:24 AM11/21/22
to blo...@googlegroups.com
The `injected` property in css.ts is private, so there's currently no way to check.  However, would wrapping your register call in a try catch work for you?

try {
  Blockly.Css.register(yourCss);
} catch (_e) {
  // Must be already injected.
}

Alternatively, you could store that you've already registered the CSS somewhere.

let hasRegistered = false;

yourFunction() {
  if (!hasRegistered) {
    Blockly.Css.register(yourCss);
    hasRegistered = true;
  }
}

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/8da52a96-5b29-4a59-a653-a1945ff8929en%40googlegroups.com.


--
Neil Fraser, Switzerland
https://neil.fraser.name
Reply all
Reply to author
Forward
0 new messages