Class page
Web process counterpart to the webview widget
The page is the web process counterpart to the webview widget; for each webview widget created on the UI process, a corresponding page instance is created in a web process.
Methods
page:eval_js (script, options)
Synchronously run a string of JavaScript code in the context of the
webview. The JavaScript will run even if the enable_javascript
property of the webview is false
, as it is run within a separate
JavaScript script world.
If the options
parameter is provided, only the source
key is
recognized; if provided, it should be a string to use in error messages.
Parameters
-
scriptType: stringThe JavaScript string to evaluate.
-
optionsType: tableOptionalDefault:
{}
Additional arguments.
Properties
page.uri
page.document
dom_document
currently loaded in the page.
page.id
A page and webview widget pair will always have the same ID; this is useful for coordinating Lua accross processes.
Signals
"document-loaded"
Emitted when the DOM document of the page has finished loading.
"send-request"
Emitted before every HTTP request is sent. By connecting to this signal one can redirect the request to a different URI, or block the request entirely. It is also possible to modify the HTTP headers sent with the request.
Redirecting a request to a different URI
To redirect a request to a different URI, return the new URI from your signal handler.
page:add_signal("send-request", function () return "http://0.0.0.0/" -- Redirect everything to localhost end)
Blocking a request
To block a request, return false
.
page:add_signal("send-request", function (_, uri) if uri:match("^http:") then return false -- Block all http:// requests end end)
Modifying HTTP headers
To modify the HTTP headers sent with the request, modify the headers
table.
page:add_signal("send-request", function (_, _, headers) headers.Referer = nil -- Don't send Referer header end)
Parameters
-
pageType: pageThe page.
-
uriType: stringThe URI of the request.
-
headersType: tableThe HTTP headers of the request.
Return Values
-
string or falseA redirect URI, or
false
to block the request.
Attribution
Copyright
- 2016 Aidan Holm