Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrustedHTML.fromLiteral is exposed in workers but assumes the current global is a Window #374

Closed
Ms2ger opened this issue Sep 16, 2022 · 1 comment
Labels
proposed-removal Issues concerning potential removal of functionality from the API
Milestone

Comments

@Ms2ger
Copy link

Ms2ger commented Sep 16, 2022

In https://w3c.github.io/trusted-types/dist/spec/#abstract-opdef-create-a-trusted-type-from-literal , TrustedHTML is special-cased to do

Let templateNode be the results of creating an element given "template", the HTML namespace and current global object's associated Document.

but the current global could be a worker global.

@lukewarlow
Copy link
Member

In this case specifically for the TrustedHTML type Chromium throws an InvalidStateError.

LocalDOMWindow* window = LocalDOMWindow::From(script_state);
if (!window) {
    exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
                                      "Cannot find current DOM window.");
    return nullptr;
}

We could spec this but it feels like the function just shouldn't be exposed for workers in this case? So the IDL could be changed to:

[Exposed=(Window,Worker)]
interface TrustedHTML {
  stringifier;
  DOMString toJSON();
  [Exposed=Window] static TrustedHTML fromLiteral(object templateStringsArray);
};

This was referenced Jan 15, 2024
@koto koto added the proposed-removal Issues concerning potential removal of functionality from the API label Jan 18, 2024
@mbrodesser-Igalia mbrodesser-Igalia added this to the v2 milestone Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposed-removal Issues concerning potential removal of functionality from the API
Projects
None yet
Development

No branches or pull requests

4 participants