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

Getting a global JavaScript function or the document object #2993

Open
aghasemi opened this issue Aug 19, 2022 · 6 comments
Open

Getting a global JavaScript function or the document object #2993

aghasemi opened this issue Aug 19, 2022 · 6 comments

Comments

@aghasemi
Copy link

Hi,

I cannot get the js.document object in Python, as expressed in the code snippets here in docs. I use ShinyPy Live. The code is here.

Am I doing something wrong? Is there some working example of accessing a global JavaScript object from within Python/Pyodide code?

Thanks

@hoodmane
Copy link
Member

Did you import js first?

@aghasemi
Copy link
Author

Did you import js first?

Yes :))))
(See the linked code)

@hoodmane
Copy link
Member

If you do import js; print(js) you see [object DedicatedWorkerGlobalScope] which means that Pyodide is running in a web worker. If you were in the main thread you would see [object Window]. So it's not possible to do direct DOM manipulation -- or if it is possible, the way to do it depends on the details of how the shiny runtime is set up.

@aghasemi
Copy link
Author

If you do import js; print(js) you see [object DedicatedWorkerGlobalScope] which means that Pyodide is running in a web worker. If you were in the main thread you would see [object Window]. So it's not possible to do direct DOM manipulation -- or if it is possible, the way to do it depends on the details of how the shiny runtime is set up.

I see. Many thanks. So there is no way to circumvent it?

@hoodmane
Copy link
Member

If the runtime is set up correctly it is possible to proxy Dom access to the main thread. But it's a bit technically complex to set up. You would have to ask the shiny folks whether they are interested in supporting such a thing if not you are out of luck.

@aghasemi
Copy link
Author

Many thanks. I did.

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

No branches or pull requests

2 participants