class

Webview::Window

Inherits Reference / Object

A webview window.

To use webview.cr, inherit this class and overload the #run method.

class MyWindow < Webview::Window
  def run
    run do
      go_to "https://crystal-lang.org"
    end
  end
end

Constants

HTML_RENDER_PREFIX = "data:text/html,"
TEXT_RENDER_PREFIX = "data:text/text,"

Constructors

new(debug = false, window = nil, title = "Crystal App")
Source

Instance methods

default_size=(dimensions : Tuple(Int32, Int32))

Set the default size of the window.

Source
eval(code : String)

Evaluate arbitrary Javascript

Source
go_to(url : String)

An alias for location= for places where the receiver can be implicit.

Source
location=(url : String)

navigate to the given URL. This is equivalent to calling window.location = url in Javascript.

Source
maximum_size=(dimensions : Tuple(Int32, Int32))

Set the maximum size the window can be resized to.

Source
minimum_size=(dimensions : Tuple(Int32, Int32))

Set the minimum size the window can be resized to.

Source
render_html(html : String)

Render the received HTML page.

This is the same as #location= with a URL that starts with "data:text/html,"

Source
render_text(text : String)

Render the received plaintext

This is the same as #location= with a URL that starts with "data:text/text,"

Source
resize(width, height)

Resize the window to a fixed value.

Source
resize_to_at_least(width, height)

Set the minimum size the window can be resized to.

Source
resize_to_at_most(width, height)

Set the maximum size the window can be resized to.

Source
run

Overload this as the entrypoint of your application, and call run from inside, setting up the webview in the block.

def run
  run do
    go_to "https://example.com"
  end
end
Source
script

This must return a string which is valid javascript, which will be executed each time a new page is loaded. It is guaranteed that code is executed before window.onload.

By default (as in, unless the class is inherited and the method overloaded), this is nil, and no code is injected.

Source
size=(dimensions : Tuple(Int32, Int32))

Set the size of the window to a fixed value.

Source
title=(new_title : String)

Set the window title.

Source
try_to_resize_to(width, height)

Set the default size of the window.

Source