w3c / w3c/DOM-Parsing

Scripting flag and behaviour for noscript

Open
#7 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
28
Forks
14
Avg merge
3h 10m
Merged PRs (30d)
1

Description

This flag determinate behaviour for noscript. Default scripting flag depends on scripting was enabled/disabled which depends if node's node document has a browsing context and scripting is enabled in that browsing context.
If needed then scripting flag can be force so we can have scripting flag set to "enabled" where scripting was disabled. Comment from HTML spec: "The scripting flag can be enabled even when the parser was originally created for the HTML fragment parsing algorithm, even though script elements don't execute in that case."
HTML fragment parsing algorithm only check scripting flag state (doesn't change it).
And now in P&S I see:

  • all commands that use fragment parsing algorithm (Element.innerHTML, Element.outerHTML, Element.insertAdjacentHTML, Range.createContextualFragment) don't set explicity a scripting flag. They operate on intermediate document without browsing context so this flag has default state "disabled" so noscript element should be parsed. But browsers don't do this so probably somewhere this flag should be set to "enabled" in P&S spec.
  • for DOMParser.parseFromString() and "text/html" you wrote "The scripting flag must be set to "disabled" but it's obvious because returned document doesn't have browsing context and second green box inform about parsing noscript element.
    Some test:
<script type = "text/javascript">
    var div = document.createElement("div");
    div.innerHTML = "<noscript><p>test1<p>test2</noscript></noscript>";
    console.log(div.firstChild.childNodes.length, div.firstChild.firstChild); // 1 text

    var div2 = document.createElement("div");
    div2.insertAdjacentHTML("afterbegin", "<noscript><p>test1<p>test2</noscript>");
    console.log(div2.firstChild.childNodes.length, div.firstChild.firstChild); // 1 text

    var frag = document.createRange().createContextualFragment("<noscript><p>test1<p>test2</noscript>");
    console.log(frag.firstChild.childNodes.length, frag.firstChild.firstChild); // 1 text

    var doc = new DOMParser().parseFromString("<body><noscript><p>test1<p>test2</noscript>", "text/html");
    console.log(doc.body.firstChild.childNodes.length, doc.body.firstChild.firstChild, doc.body.firstChild.lastChild); // 2 p p 
    console.log(doc.defaultView); // null - this new document is without browsing context
</script>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the DOM Parsing specification sections for Element.innerHTML, outerHTML, insertAdjacentHTML, Range.createContextualFragment, and DOMParser.parseFromString, then compare them with the cited HTML fragment parsing and scripting-flag algorithms. Done means the specification clearly defines scripting-flag behavior for these APIs and matches the noscript examples described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
html
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.