Skip to content

A port of rust-headless-chrome to Luau, built for Lune

License

Notifications You must be signed in to change notification settings

synpixel/chrome.luau

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chrome

This package is a port of rust-headless-chrome to Luau, built for Lune.

Installation

pesde

pesde add synpixel/chrome

Quick Start

local fs = require("@lune/fs")
local chrome = require("@pkg/chrome")

local browser = chrome.Browser.new()
local tab = browser:newTab()

-- Navigate to wikipedia
tab:navigateTo("https://www.wikipedia.org"):waitUntilNavigated()

-- Wait for network/javascript/dom to make the search-box available
-- and click it.
tab:waitForElement("input#searchInput"):click()

-- Type in a query and press `Enter`
tab:typeText("WebKit"):pressKey("Enter"):waitUntilRedirect()

-- We should end up on the WebKit-page once navigated
local element = tab:waitForElement("#firstHeading")
assert(tab:getUrl():sub(-6) == "WebKit")

-- Take a screenshot of the entire browser window
local jpeg = tab:captureScreenshot({ format = "jpeg", fromSurface = true })
-- Save the screenshot to disc
fs.writeFile("screenshot.jpeg", jpeg)

-- Take a screenshot of just the WebKit-Infobox
local png = tab:waitForElement("#mw-content-text > div > table.infobox.vevent"):captureScreenshot({ format = "png" })
-- Save the screenshot to disc
fs.writeFile("screenshot.png", png)

-- Run JavaScript in the page
local result = element:callJsFunction([[
    function getIdTwice () {
        // `this` is always the element that you called `callJsFunction` on
        const id = this.id;
        return id + id;
    }
]])

assert(result.value == "firstHeadingfirstHeading")

About

A port of rust-headless-chrome to Luau, built for Lune

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages