Patch js.document out of the box (#1880)

* Patch js.document out of the box

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Andrea Giammarchi
2023-12-04 17:53:13 +01:00
committed by GitHub
parent 06e1fdecc2
commit 8e5605fa42
2 changed files with 6 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ from pyscript.util import NotSupported
RUNNING_IN_WORKER = not hasattr(globalThis, "document")
if RUNNING_IN_WORKER:
import js
import polyscript
PyWorker = NotSupported(
@@ -13,6 +14,7 @@ if RUNNING_IN_WORKER:
)
window = polyscript.xworker.window
document = window.document
js.document = document
sync = polyscript.xworker.sync
# in workers the display does not have a default ID

View File

@@ -6,3 +6,7 @@ display("Hello World", target="test", append=True)
print("sleeping")
sync.sleep(1)
print("awake")
import js
js.document.body.append("document patch ")