<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>307412</bug_id>
          
          <creation_ts>2026-02-09 22:35:44 -0800</creation_ts>
          <short_desc>&lt;audio&gt; and &lt;video&gt; controls work in HTML namespace and when added in SVG, MathML or other, it throws error</short_desc>
          <delta_ts>2026-07-30 07:40:30 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Media</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar, WPTImpact</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ahmad Saleem">ahmad.saleem792</reporter>
          <assigned_to name="Ahmad Saleem">ahmad.saleem792</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2179755</commentid>
    <comment_count>0</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-02-09 22:35:44 -0800</bug_when>
    <thetext>Hi Team,

While exploring console errors in below WPT test case (which leads to harness failure as well):

WPT Test Case - https://wpt.fyi/results/svg/interact/scripted/tabindex-focus-flag.svg?label=master&amp;label=experimental&amp;aligned&amp;q=tabindex-focus

*** Console Error *** (It changes) and hence, this is skipped test at the moment:

[Error] TypeError: undefined is not an object (evaluating &apos;this.rightContainer.element.style.removeProperty&apos;)
    layout
    width
    _updateControlsSize
    _updateControlsIfNeeded
    MediaController
    createControls
[Error] TypeError: undefined is not an object (evaluating &apos;this.rightContainer.element.style.removeProperty&apos;)
    layout
    (anonymous function)
    forEach
    performScheduledLayout
    _layout
    _frameDidFire

******

This comes from our media controls implementation, which creates &lt;div&gt; in HTML namespace here:

WebKit Source: https://raw.githubusercontent.com/WebKit/Webkit/HEAD/Source/WebCore/Modules/modern-media-controls/controls/layout-node.js

```
function elementFromString(elementString)
{
    const element = document.createElement(&quot;div&quot;);
    element.innerHTML = elementString;
    return element.firstElementChild;
}

```

We need to update to handle SVG, MathML namespaces correctly and work accordingly.

Based on Claude, this does without regressing performance - because XHTML namespace is more common, we need fast path for that:

```
function elementFromString(elementString)
{
    // Fast path: Use simple method for HTML documents
    const ownerDoc = document;
    const isHTMLDocument = ownerDoc.documentElement instanceof HTMLHtmlElement;
    
    if (isHTMLDocument) {
        // Original fast method - works fine in HTML context
        const temp = document.createElement(&quot;div&quot;);
        temp.innerHTML = elementString;
        return temp.firstElementChild;
    }
    
    // Slow path: Only for SVG/MathML/XML documents
    return elementFromStringWithNamespace(elementString, ownerDoc);
}

function elementFromStringWithNamespace(elementString, ownerDoc)
{
    const parser = new DOMParser();
    const doc = parser.parseFromString(elementString, &apos;text/html&apos;);
    const parsed = doc.body.firstElementChild;
    
    if (!parsed) {
        return ownerDoc.createElementNS(&apos;http://www.w3.org/1999/xhtml&apos;, &apos;div&apos;);
    }
    
    const imported = ownerDoc.importNode(parsed, true);
    
    // Verify and fix namespace if needed
    if (imported.namespaceURI !== &apos;http://www.w3.org/1999/xhtml&apos;) {
        return recreateInHTMLNamespace(parsed, ownerDoc);
    }
    
    return imported;
}

function recreateInHTMLNamespace(sourceElement, ownerDoc)
{
    const element = ownerDoc.createElementNS(&apos;http://www.w3.org/1999/xhtml&apos;, sourceElement.localName);
    
    for (const attr of sourceElement.attributes) {
        element.setAttribute(attr.name, attr.value);
    }
    
    for (const child of sourceElement.childNodes) {
        if (child.nodeType === Node.ELEMENT_NODE) {
            element.appendChild(recreateInHTMLNamespace(child, ownerDoc));
        } else if (child.nodeType === Node.TEXT_NODE) {
            element.appendChild(ownerDoc.createTextNode(child.textContent));
        }
    }
    
    return element;
}

```

Just raising, so we can track and fix it.

Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2182297</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2026-02-16 22:36:33 -0800</bug_when>
    <thetext>&lt;rdar://problem/170528402&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2235675</commentid>
    <comment_count>2</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2026-07-30 07:40:30 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/70528</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>