Skip to content

Document does not have target element set before script can access it on load event #10914

@shannonbooth

Description

@shannonbooth

What is the issue with the HTML Standard?

This can be seen in the WPT test: https://github.com/web-platform-tests/wpt/blob/master/url/data-uri-fragment.html

From what I can gather from the standard, nothing will update the target element of the document by the time that:

window.addEventListener('load', function() {
    document.getElementById('foo').matches(':target')
}

Is run for the iframe.

On a new document, "Update the document for history step application" invokes "try to scroll to the fragment", which schedules a task which polls for the documents indicated part to be set. By this point, scripts may run for the document. Nothing relevant to this test appears as if it would delay the load event before setting the fragment has had the chance to complete with a <p> element inserted into the document.

There is a definite chance I am misreading / misunderstanding how this is meant to work, but it is actually unclear to me if any section of the spec is guaranteed to end up setting the target fragment at all. It does not seem like "try to scroll to the fragment" could achieve that, as by the time the task runs, the HTML parser may have stopped. Delaying the load event isn't enough, as the parser has stopped by that point from what I understand.

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