Skip to content

Asynchronous createHTML/createScript/createScriptURL #588

Open

Description

@fred-wang

Testcase:

<!DOCTYPE html>
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script';">
<div id="div"></div>
<script>
  trustedTypes.createPolicy("default", {
    createHTML: async s => s,
  });
  div.innerHTML = "Hello World!"
</script>

This sets the div's inner HTML to [object Promise] in all browsers, which at first was kinda unexpected to me.

Technically, an async function is equivalent to returning a Promise object, and it's unclear whether "stringifying" in "Process value with a default policy" is supposed to resolve that promise. So that's a special case of #541

cc @lukewarlow

Activity

  1. lukewarlow commented on Jun 26, 2025

    @lukewarlow
    Member

    I think that or throwing is about the only reasonable outcome there.

  2. annevk commented on Jun 26, 2025

    @annevk
    Member

    This behavior seems kinda expected and probably not different from any other place that takes a callback. Being strict about the return type, but only for certain types, seems weird.

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

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