Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

338
Views
Dynamic script activation fails with Blazor Server in Firefox

In a Blazor Server (.NET Core 6) application, I have this test html/head/script element:

<script type="text/plain" data-consent-category="google" defer>
    alert("Google Analytics loaded");
</script>

When a user presses a consent button, a piece of code is executed:

function ApplyPreferencesAbbreviatedCode() {
    let activatableScriptTags = document.querySelectorAll("script[type='text/plain']");
    activatableScriptTags.forEach(element => {
        let requiredCategory = element.getAttribute("data-consent-category");
        let clonedElement = element.cloneNode(true);
        clonedElement.setAttribute("type", "text/javascript");
        element.parentElement.insertBefore(clonedElement, element.nextSibling);
        element.remove();
    });
}

This works fine in Edge but does nothing in Firefox. How can I dynamically load scripts in a way that works in Blazor Server/Firefox (it should work with script elements with and without a src attribute).

Note: not having the defer attribute will cause the element to be stripped by Blazor Server (although it is supposed to not have any semantics when there is no src attribute as well).

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!