Open Bug 957054 Opened 12 years ago Updated 8 months ago

Don't preload scripts with unknown types

Categories

(Core :: DOM: HTML Parser, task, P3)

task

Tracking

()

People

(Reporter: hsivonen, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: good-first-bug, parity-chrome, parity-safari)

Attachments

(2 files)

Bulk-downgrade of unassigned, 4 years untouched DOM/Storage bugs' priority.

If you have reason to believe this is wrong (especially for the severity), please write a comment and ni :jstutte.

Severity: normal → S4
Priority: -- → P5

Chrome has fixed their corresponding bug: https://bugs.chromium.org/p/chromium/issues/detail?id=626321

Severity: S4 → S3
Keywords: good-first-bug
Priority: P5 → P3

If chrome as fixed their corresponding bug does it also gets fixed on mozilla? If not then i would like to work on this bug.

(In reply to yanshrey from comment #4)

If not then i would like to work on this bug.

That would be great. See https://searchfox.org/mozilla-central/rev/1ebc9745be02eebf7a694f5c527a44a045b8c97a/parser/html/nsHtml5TreeBuilderCppSupplement.h#207 for the starting point.

Hi,
Is anyone still working on this bug?
If not want to give it a shot

I was looking into but but you can also go ahead and try it.
Check comment #5

Fixing bug 1848311 would have the side effect of fixing this.

Not only should we not preload unknown type, we should not create speculations when seeing unknown types.

From the bug I marked as duplicate:

We should check for IE event handler scripts and unsupported type/language combinations in the HTML parser already (not just in ScriptLoader) to avoid creating speculations or preloads for scripts that will not execute anyway.

Based on
https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script

This affects mSpeculativeLoadQueue. I didn't change the behavior of
mCurrentHtmlScriptCannotDocumentWriteOrBlock.

Assignee: nobody → mathew.hodson
Status: NEW → ASSIGNED
Type: defect → task
Attachment #9379383 - Attachment description: Bug 957054 - Don't preload scripts with unknown type r?smaug → WIP: Bug 957054 - Don't preload scripts with unknown type

I'm currently stuck trying to implement your suggestion to handle ScriptKind::eEvent like mozilla::dom::IsScriptEventHandler does. There isn't an nsHtml5AttributeName::ATTR_EVENT that I would need to detect an event attribute on a <script> element.

Flags: needinfo?(hsivonen)

Sorry about the delay. Indeed, ATTR_EVENT is needed and missing. I'm adding it in bug 1884108.

Flags: needinfo?(hsivonen)

This good-first-bug hasn't had any activity for 2 months, it is automatically unassigned.
For more information, please visit BugBot documentation.

Assignee: mathew.hodson → nobody
Status: ASSIGNED → NEW
Assignee: nobody → mathew.hodson
Status: NEW → ASSIGNED
Attachment #9379383 - Attachment description: WIP: Bug 957054 - Don't preload scripts with unknown type → Bug 957054 - Don't preload scripts with unknown type
See Also: → 1975128
Attachment #9379383 - Attachment description: Bug 957054 - Don't preload scripts with unknown type → Bug 957054 - Don't preload scripts with unknown type r=smaug

@smaug do you think you could land this for me? Or do you think it shouldn't land unless we add a new wpt for it?

Flags: needinfo?(smaug)

I think this could use a test, if just possible. The change isn't trivial.

Flags: needinfo?(smaug)
Depends on: 1651513

I modified some existing WPT that check for speculative load. Can you land this for me if everything looks good?

Flags: needinfo?(smaug)
Flags: needinfo?(smaug)

Which patches need landing? The stack in phabricator has 3 patches

Flags: needinfo?(mathew.hodson)

All three need to land. First the two for this bug 957054, and then the one in bug 1975128 since it depends on the changes in IsScriptEventHandler

Flags: needinfo?(mathew.hodson)

Hopefully it worked :)

Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/53999 for changes under testing/web-platform/tests
Blocks: 1674583
No longer blocks: 1674583
Flags: needinfo?(mathew.hodson)

Used explicit namespaces to fix nonunified build errors. Verified with ac_add_options --disable-unified-build and I didn't see any other failures in the treeherder link.

Could you land this again?

Flags: needinfo?(mathew.hodson) → needinfo?(smaug)
Blocks: 1674583
Status: ASSIGNED → RESOLVED
Closed: 11 months ago
Resolution: --- → FIXED
Target Milestone: --- → 143 Branch
Upstream PR merged by moz-wptsync-bot
Upstream PR merged by moz-wptsync-bot
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Target Milestone: 143 Branch → ---
Status: REOPENED → RESOLVED
Closed: 11 months ago11 months ago
Resolution: --- → FIXED
Target Milestone: --- → 143 Branch
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Target Milestone: 143 Branch → ---
Failed to create upstream wpt PR due to merge conflicts. This requires fixup from a wpt sync admin.
Flags: needinfo?(smaug) → needinfo?(james)
Status: REOPENED → RESOLVED
Closed: 11 months ago11 months ago
Resolution: --- → FIXED
Target Milestone: --- → 143 Branch
Flags: needinfo?(james) → needinfo?(aborovova)
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/54068 for changes under testing/web-platform/tests
Flags: needinfo?(aborovova)
Upstream PR merged by moz-wptsync-bot
Regressions: 1981985
Regressions: 1980426
No longer regressions: 1980426
Pushed by chorotan@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/b5a01df6d65f https://hg.mozilla.org/integration/autoland/rev/26331ad8f0c8 Revert "Bug 957054 - Test that unsupported script types don't speculatively load r=smaug" on request by smaug
Status: RESOLVED → REOPENED
Flags: needinfo?(smaug)
Resolution: FIXED → ---
Target Milestone: 143 Branch → ---

Pushed by chorotan@mozilla.com:
https://github.com/mozilla-firefox/firefox/commit/9c44d5da4225
https://hg.mozilla.org/releases/mozilla-beta/rev/2e0c099f88fc
Revert "Bug 957054 - Test that unsupported script types don't speculatively load r=smaug" on request by smaug

Status: REOPENED → RESOLVED
Closed: 11 months ago11 months ago
Resolution: --- → FIXED
Status: RESOLVED → REOPENED
Resolution: FIXED → ---

Should I update the patch to do the more narrow change that's just for mSpeculativeLoadQueue and not change the way mCurrentHtmlScriptCannotDocumentWriteOrBlock is set?

Flags: needinfo?(hsivonen)
Attachment #9379383 - Attachment description: Bug 957054 - Don't preload scripts with unknown type r=smaug → WIP: Bug 957054 - Don't preload scripts with unknown type

(In reply to Mathew Hodson from comment #40)

Should I update the patch to do the more narrow change that's just for mSpeculativeLoadQueue and not change the way mCurrentHtmlScriptCannotDocumentWriteOrBlock is set?

Rather than generating two kinds of tree ops based on boolean mCurrentHtmlScriptCannotDocumentWriteOrBlock: execute script that may document.write or block and execute script that cannot document.write or block, there should be a third category: Scripts that must not be executed, so that the HTML parser's classification decision is final and the script execution code path doesn't get an opportunity to disagree.

We already have opPreventScriptExecution, but it doesn't perform a microtask checkpoint. From reading the spec, it looks to me that a new tree op opPreventScriptExecutionWithMicrotaskCheckpoint is needed. (When the spec pops a script off the stack at EOF, it prevents execution without a microtask checkpoint. However, when a script end tags is processed, a microtask checkpoint is performed before looking at the scripts type, etc.)

Flags: needinfo?(hsivonen)

(That is, let's not simply change mSpeculativeLoadQueue, because the path for executing a script that may document.write or block is expensive, so if we know we don't want to execute the script, it makes sense to do something less expensive. We just need the decision to be final.)

Flags: needinfo?(smaug) → needinfo?(james)
Flags: needinfo?(james) → needinfo?(aborovova)
Flags: needinfo?(aborovova)

(In reply to Henri Sivonen (:hsivonen) from comment #41)

We already have opPreventScriptExecution, but it doesn't perform a microtask checkpoint. From reading the spec, it looks to me that a new tree op opPreventScriptExecutionWithMicrotaskCheckpoint is needed. (When the spec pops a script off the stack at EOF, it prevents execution without a microtask checkpoint. However, when a script end tags is processed, a microtask checkpoint is performed before looking at the scripts type, etc.)

Are there existing tests in this area I could look at? Sounds like we need a new test that checks script execution, and the WPTs I added for speculative fetching aren't sufficient.

QA Whiteboard: [qa-triage-done-c144/b143]
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/54752 for changes under testing/web-platform/tests
Upstream PR merged by moz-wptsync-bot

This good-first-bug hasn't had any activity for 2 months, it is automatically unassigned.
For more information, please visit BugBot documentation.

Assignee: mathew.hodson → nobody
Status: REOPENED → NEW
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: