Skip to content
New issue

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

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

Already on GitHub? # to your account

bindProcs issue: CONSOLE JS ERROR ReferenceError: Can't find variable: api #20

Open
yaroslav-gwit opened this issue Dec 16, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@yaroslav-gwit
Copy link
Contributor

yaroslav-gwit commented Dec 16, 2022

Hello again. Could you please help me out with this error message?
It shows up in the Nim console:

index.html#loaded:53:4: CONSOLE JS ERROR ReferenceError: Can't find variable: api

Code snippets I used:
app.nim

import webgui
import os
import strutils
import osproc

let app = newWebView(currentHtmlPath(), "Window Title", 650, 610)

app.bindProcs("api"):
  proc callback() = echo execCmd("echo 'Nim is awesome'")

app.run()
app.exit()

index.html button

<button onclick="api.callback()" type="button" class="btn btn-warning m-1" style="min-width: 170px;">Remind me later</button>
@juancarlospaco
Copy link
Owner

OS ?, Nim version ?

Please run the code, open the inspector,
and in JavaScript run window.external and send screenshot, if possible showing the autocomplete,
I need to know if you have window.external.* defined in JS in the window.

@juancarlospaco juancarlospaco added the bug Something isn't working label Dec 16, 2022
@yaroslav-gwit
Copy link
Contributor Author

Version: Nim Compiler Version 1.6.8 [Linux: amd64]
OS: PopOS 22.04

window.external is undefined:

> window.external
< undefined

@juancarlospaco
Copy link
Owner

So looks like it is in fact broken, but it is not my code,
it seems something upstream has broken compatibilities, that sux.

@danielRi
Copy link

danielRi commented Sep 11, 2024

Hi @juancarlospaco , I have the same problem

webgui [(version: 0.9.0, checksum: d5f8f29259032cbebc5b1bf48548facf5b3534a7)]
macOs 14.5
Nim Compiler Version 2.0.8 [MacOSX: amd64]

main.nim

import webgui
let app = newWebView "/path/to/index.html"

app.bindProcs("api"):
  proc callback() = echo "hello"

app.run()
app.exit()

index.html

<button onclick="api.callback()"> Run JavaScript </button>
Bildschirmfoto 2024-09-11 um 09 07 30

I would really love to use the package and build something. Is there anything I can do?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants