瀏覽代碼

LibWeb: Set script force async to false when async changes

Jamie Mansfield 11 月之前
父節點
當前提交
bedb626c29

+ 1 - 0
Tests/LibWeb/Text/expected/HTML/script-async-attribute.txt

@@ -1,2 +1,3 @@
 includeScript.async = false
 script.async = true
+script.async = false

+ 4 - 0
Tests/LibWeb/Text/input/HTML/script-async-attribute.html

@@ -7,5 +7,9 @@
 
         const script = document.createElement("script");
         println(`script.async = ${script.async}`);
+
+        script.setAttribute("async", "true");
+        script.removeAttribute("async");
+        println(`script.async = ${script.async}`);
     });
 </script>

+ 4 - 0
Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp

@@ -66,6 +66,10 @@ void HTMLScriptElement::attribute_changed(FlyString const& name, Optional<String
         if (!is_parser_inserted() && is_connected() && value.has_value() && !old_value.has_value()) {
             prepare_script();
         }
+    } else if (name == HTML::AttributeNames::async) {
+        // https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model:script-force-async
+        // When an async attribute is added to a script element el, the user agent must set el's force async to false.
+        m_force_async = false;
     }
 }