User Interaction DOMException /Issue

38 views
Skip to first unread message

Irina Lipov

unread,
Nov 7, 2019, 8:59:51 AM11/7/19
to netlogo-devel
Hi,
I am developing a web application. It has an iframe with netlogo source

<iframe id="iframe"  src="/web?/assets/modelslib/Code Examples/MyExamle.nlogo"  width="850" height="600" >
</iframe>

It can`t start working because of html5-browser restriction
(Developer tools browser console reports the following error:
Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first)

I tried to add iframe parameters like allow="autoplay" muted = "meted", autoplay="true". Without success

I tried to simulate user interaction running command
iframe.contentWindow.workspace.evalPrims.runCode("user-yes-or-no?", false, {"Start"}) (Get strange errors about tokens - Unexpected token '}')

The question is actually how can I solve the issue :
  1. My be  someone know how to configure iframe parameters to cancel user interaction need? 
  2. How can I use API to run user interaction primitive code? (Is there an option to run hidden it and transfer "yes/ok" by user in code?)
  3. Is the other API to simulate user interaction without actualy ineracting with use?
Thanks 

--
Best,
Irena

Jeremy Baker

unread,
Nov 7, 2019, 11:05:12 AM11/7/19
to netlogo-devel
Hey Irina,

I'm not aware of any media elements used by NetLogo Web that would need to have a `play()` method called, and I believe those would be the source of the error you're seeing.  Do you other video or audio elements added to your page or elsewhere in your code that might be causing the exception?  If you do, there are docs on MDN on how to get things playing properly.

Your `iframe` should load the model from the query string with no other interaction required when using the `/web` page from Galapagos.

-Jeremy

Benjamin Hoffmann

unread,
Apr 27, 2020, 9:05:39 AM4/27/20
to netlogo-devel
Hi, 

i would still be interested in an answer to point number 2: How can I use the API to interact with the user. In other words, is it possible to have an extension (in java) display a message dialog in netlog to the user?

Jeremy Baker

unread,
May 1, 2020, 11:13:12 AM5/1/20
to netlogo-devel
Hey Benjamin,

You can definitely interact with the user from an extension.  Maybe the most direct example of that is [the Dialog extension](https://github.com/NetLogo/Dialog-Extension), which prompts users for strings or for confirmation in a way that's compatible with NetLogo Web.  The [Fetch extension](https://github.com/NetLogo/Fetch-Extension) prompts the model user with a file select dialog with `user-file` and `user-file-async`.

Another way to interact is via a menu entry on the NetLogo menu bar, and [the Python extension](https://github.com/NetLogo/Python-Extension) is a good example of this.  When you have config info you want to set, this is a good way to give access to it.

I don't know exactly what you're trying to achieve, but my advice would be if you can make your extension primitives interact with the built in `user-*` primitives or the Dialog extension primitives, that'd be preferable to rolling your own inputs.  Of course if the info you need from the user is more complex than strings and files that may not be possible.

Hope that helps.

-Jeremy
Reply all
Reply to author
Forward
0 new messages