package
0.5.0
Repository: https://github.com/metafates/mangal-lua-libs.git
Documentation: pkg.go.dev

# README

Headless

Headless chrome Lua port.

If you don't have a headless Chrome installed it will be downloaded and installed automatically on the first launch.

Types

  • Headless
  • Browser
  • Page
  • Element

Headless

FunctionReturn
browserbrowser

Browser

FunctionArgumentsReturn
pageoptional string (url)page

Page

FunctionArgumentsDescriptionReturn
waitLoadwaits for the window.onload event, it returns immediately if the event is already fired.
elementstringretries until an element in the page that matches the CSS selector, then returns the matched element.element
elementRstring, stringretries until an element in the page that matches the css selector and it's text matches the jsRegex, then returns the matched element.element
elementsstringreturns all elements that match the css selector[]element
elementByJSstringreturns the element from the return value of the js function. If sleeper is nil, no retry will be performed. By default, it will retry until the js function doesn't return null. To customize the retry logic, check the examples ofelement
waitElementsMoreThanstring, numberWait until there are more than elements.
navigatestringNavigate to the url. If the url is empty, "about:blank" will be used. It will return immediately after the server responds the http header.
hasstringHas an element that matches the css selectorboolean
evalstringEvaluate js function on the page. Will return a value if any is returnedstring
htmlstringHTML of the pagestring

Element

FunctionArgumentsDescriptionReturn
inputstringInput focuses on the element and input text to it. Before the action, it will scroll to the element, wait until it's visible, enabled and writable. To empty the input you can use something like input("")
clickClick will press then release the button just like a human. Before the action, it will try to scroll to the element, hover the mouse over it, wait until the it's interactable and enabled.
textText that the element displaysstring
attributestringAttribute of the element.string
htmlHTML of the elementstring
propertystringProperty of the DOM objectstring

Property vs Attribute

Example

local headless = require("headless")
local browser = headless.browser()
local page = browser:page()
page:navigate("https://www.google.com")
page:waitLoad()
local element = page:element("input[name='q']")
element:input("lua")
local button = page:element("button[name='btnK']")
button:click()
page:waitLoad()
print(page:html())

This example was generated by GitHub copilot, lol. I didn't test but looks legit.

# Functions

No description provided by the author
No description provided by the author