Skip to content

HtmlPage: fix a bug where async script may not be executed#1100

Merged
rbri merged 1 commit intoHtmlUnit:masterfrom
duonglaiquang:duong_postponed
Mar 13, 2026
Merged

HtmlPage: fix a bug where async script may not be executed#1100
rbri merged 1 commit intoHtmlUnit:masterfrom
duonglaiquang:duong_postponed

Conversation

@duonglaiquang
Copy link
Contributor

This PR does the following

Fix HtmlPage to flush postponed actions (including async scripts) before executing deferred scripts during page initialization.

Problem

Since bca4c02, async <script> tags are added to the postponed actions queue via engine.addPostponedAction() instead of page.addAfterLoadAction().

The postponed actions queue is normally drained after synchronous script execution or event dispatch.
However, if a page has an async script with no subsequent synchronous scripts and no event handlers, the async script is silently ignored.

<html>
<head>
  <script async src="async.js"></script>
</head>
</html>

@sonarqubecloud
Copy link

@rbri rbri merged commit b0ba772 into HtmlUnit:master Mar 13, 2026
8 checks passed
@rbri
Copy link
Member

rbri commented Mar 13, 2026

this breaks org.htmlunit.javascript.PostponedActionTest.loadingJavaScript()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants