- From: Andrea Giammarchi <notifications@github.com>
- Date: Mon, 31 Jul 2023 05:13:27 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/1217/1658254127@github.com>
> DOM APIs are massively interlinked with style and rendering
but `(new DOMParser).parseFromString(...)` works already, right? I am not sure, if stuff is never live, how this API could be problematic once exposed via Worker :thinking:
- - -
I went ahead and did a test ... the iframe hack is awkward (it needs a `sandbox` that apparently allows a different thread and at the same time is discouraged and it warns but it's needed for worker to execute).
**index.html**
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<iframe src="iframe.html"
sandbox="allow-scripts allow-same-origin"
frameborder="0" width="0" height="0"
style="position:absolute;top:-1px;left:-1px"
></iframe>
</body>
</html>
```
**iframe.html**
```html
<!DOCTYPE html>
<script type="module">
import coincident from '../../window.js';
coincident(new Worker('./worker.js', {type: 'module'}));
</script>
```
**worker.js**
```js
import coincident from '../../window.js';
const {window} = coincident(self);
const parser = new window.DOMParser;
const document = parser.parseFromString(
'<!doctype html>',
'text/html'
);
document.body.textContent = 'Hello World';
console.log(document.documentElement.outerHTML);
// <html><head></head><body>Hello World</body></html>
```
I believe this would cover @BenjaminAster non-blocking use case via a whole DOM API that *should* not execute among the *main* but I couldn't find any encouraging discussion around this assumption, yet it seems to be de-facto standard.
[Live here](https://webreflection.github.io/coincident/test/iframe/).
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1217#issuecomment-1658254127
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/dom/issues/1217/1658254127@github.com>
Received on Monday, 31 July 2023 12:13:32 UTC