naqvis / webview

Crystal bindings to Webview library
MIT License
93 stars 8 forks source link

Question : How do you specify the path to a local web page (html file) to be displayed (served by) Webview #9

Closed serge-hulne closed 2 years ago

serge-hulne commented 2 years ago

I tried:

require "webview"

# wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", "http://127.0.0.1:3000", true)
wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView", "mint/dist/index.html")
wv.run
wv.destroy

wv.bind("myAlert", Webview::JSProc.new { 
  pp "My Alert !"
  JSON::Any.new("My Alert")
})

I tried with absolute path, then with: "mint/dist/index.html" and then with: "./mint/dist/index.html" and "../mint/dist/index.html"

But it didn't work.

naqvis commented 2 years ago

You can't simply pass the path of File for webview browser to open. You will have to either provide a URL of web server or use Data URL with data:text/html, XXXXXX where XXXXX are the HTML contents.

Please bear in mind that data urls have some limitations on the size of data which is passed and it varies from browser to browser.

Example provide in README make use of both techniques mentioned above.

serge-hulne commented 2 years ago

Thank you.