Skip to content

Custom elements cannot be used inside content scripts on extensions (v4 to v5 regression) #14739

@ceifa

Description

@ceifa

Describe the bug

After upgrading to svelte 5, I cannot use anymore custom elements that was already mounted on the page inside content scripts on my chrome extension.

The bug apparently it's because svelte 5 now rely on window.customElements, which is not available inside content scripts.

I think it is just a matter of adding a check if typeof window.customElements is undefined or not, to fallback to the previous solution that worked on v4.

Reproduction

  1. Create a page and add a custom element <foo-bar>
  2. Create a chrome extension for that page and mount a svelte component on it that uses the <foo-bar>

Logs

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'get')
    at set_custom_element_data
    at update_reaction
    at update_effect

System Info

System:
    OS: Windows 11 10.0.22635
    CPU: (6) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
    Memory: 2.23 GB / 15.92 GB
  Binaries:
    Node: 22.10.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
    npm: 11.0.0 - C:\Program Files\nodejs\npm.CMD
    bun: 1.1.29 - ~\AppData\Roaming\npm\bun.CMD
  Browsers:
    Chrome: 131.0.6778.140
    Edge: Chromium (127.0.2651.8)
    Internet Explorer: 11.0.22621.3566

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions