web-platform-tests / web-platform-tests/interop
JS Module Scripts in more contexts (2027 edition)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 524
- Forks
- 35
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 10
Description
Description
ECMA262 specifies two kinds of goal symbols for JavaScript: (classic) scripts and modules. The JS ecosystem keeps moving towards using modules, both on the web platform and server-side runtimes, both as an authoring and distribution format, however not every browser supports them in every context. This issue is about improving interoperability for JS modules in contexts where browser support is already existent but partial, in particular, XHTML documents, SVG documents, but also Web Extensions if they are in the scope of the Interop project, which I am unsure of.
This was previously submitted for Interop 2025 (see #869). While not accepted at the time, there still has been some progress in this area since then:
- every major browser now supports JS modules in Service Workers in web content
- a new API for running Web Extensions has been added to WPT, through which this area could likely be tested nowadays
Specification
See https://tc39.es/ecma262/#sec-modules for the main spec defining modules though this issue is more about their integration in multiple other consuming specs (see links below)
web-feature
web-features: js-modules
Test Links
<script type="module">in HTML documents with XML syntax (aka XHTML documents) : https://wpt.fyi/results/html/semantics/scripting-1/the-script-element/module/module-in-xhtml.xhtml<script type="module">in SVG documents : https://wpt.fyi/results/svg/interact/scripted/module-01.svg- HTML namespaced
<script type="module">in SVG documents : TBD "type": "module"for background scripts defined via the"background.service_worker"key in Web Extension Manifests: TBD
Additional Signals
Site Breakage and Workaround
Code expected to be consumed as JS modules (using syntax-enabled features such as static imports, top-level await or whose execution should be deferred) can not be run everywhere.
For example, one can not write a module that runs both in a HTML document, a XHTML document, and a SVG document. Also one can not write a Web Extension Service Worker background script that runs in every browser.
Currently, instead of being able to distribute isomorphic code using only JS modules, multiple distribution targets are required.
Current State of the Feature
Use share for JS modules on the web keeps increasing: https://chromestatus.com/metrics/webfeature/timeline/popularity/47
Integration specs, existing tests, documentation, browser bugs and implementation status
This issue is about improving interoperability for JS modules in contexts where browser support is already partial, such as:
<script type="module">in HTML documents with XML syntax (aka XHTML documents)- WHATWG spec: https://html.spec.whatwg.org/multipage/scripting.html#attr-script-type
- WPT: https://wpt.fyi/results/html/semantics/scripting-1/the-script-element/module/module-in-xhtml.xhtml
- MDN documentation: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script#module
- Blink bug: https://issues.chromium.org/issues/40518469 (33 votes)
- Gecko bug: TBD (already implemented)
- Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=227469
<script type="module">in SVG documents- W3C spec: https://svgwg.org/svg2-draft/interact.html#ScriptElement (incomplete)
- MDN documentation: https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/script#type (incomplete)
- WPT: https://wpt.fyi/results/svg/interact/scripted/module-01.svg
- Blink bug: https://issues.chromium.org/issues/40067618 (5 votes)
- Gecko bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1839954 (already implemented)
- Webkit bug: TBD
- HTML namespaced
<script type="module">in SVG documents- W3C spec: https://www.w3.org/TR/SVG2/struct.html#HTMLMetadataElements
- MDN documentation: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script#module
- WPT: TBD
- Blink bug: TBD
- Gecko bug: TBD (already implemented)
- Webkit bug: TBD
"type": "module"for background scripts defined via the"background.service_worker"key in Web Extension Manifests- WECG spec: https://w3c.github.io/webextensions/specification/index.html#key-background (incomplete)
- WPT: TBD
- Chrome documentation: https://developer.chrome.com/docs/extensions/reference/manifest/background
- MDN documentation: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/background
- Blink bug: TBD (already implemented)
- Gecko bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1775574 (7 votes)
- Webkit bug: TBD (already implemented)
Out of scope features
See the previous issue for examples of other contexts / integration points where JS modules could be added, but are not yet supported in any browser AFAIK.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing WPT cases at html/semantics/scripting-1/the-script-element/module/module-in-xhtml.xhtml and svg/interact/scripted/module-01.svg, along with the linked HTML, SVG, and WebExtensions specifications. Clarify which contexts are in scope and which missing tests are needed. Done means the selected contexts have agreed interoperability coverage and documented browser results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100