Skip to content

Bug: copyStyleSheetsToWindow() may fail if win.document.head is null #9186

Description

@ai-bughunter

Bug: copyStyleSheetsToWindow() may fail if win.document.head is null

Severity: Low
Files: src/js/utils/dom.js
Lines: 889, 898

Description

The function appends elements to win.document.head without checking if head exists. If the target window (e.g., a Picture-in-Picture window) is closing or in an invalid state, win.document.head could be null, causing an uncaught TypeError.

Affected code

win.document.head.appendChild(style);  // Line 889
// ...
win.document.head.appendChild(link);   // Line 898

Suggested fix

const head = win.document.head || win.document.documentElement;
if (head) {
  head.appendChild(style);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions