Browser & Context API
Browser Methods
Section titled “Browser Methods”browser:attach([opts])
Section titled “browser:attach([opts])”Returns a Page object.
| Option | Type | Default | Description |
|---|---|---|---|
url |
string | about:blank |
Initial URL |
reuse |
boolean | true |
Reuse a blank tab if available |
browserContextId |
string | - | Attach to a specific isolated context |
local page = browser:attach()-- or with optionslocal page = browser:attach({ url = "https://example.com", reuse = false })browser:new_context()
Section titled “browser:new_context()”Creates an isolated session. Returns a Context object.
local ctx = browser:new_context()local page = ctx:attach("https://example.com")browser:close()
Section titled “browser:close()”Closes the browser and kills the process.
browser:close()browser:get_user_data_dir()
Section titled “browser:get_user_data_dir()”Returns the profile path.
local profile = browser:get_user_data_dir()log("Profile: " .. profile)browser:call(method, params)
Section titled “browser:call(method, params)”Raw browser-level CDP command.
browser:wait_event(event, [timeout_ms], [predicate])
Section titled “browser:wait_event(event, [timeout_ms], [predicate])”Wait for a browser-level CDP notification.
browser:attach_session(target_id)
Section titled “browser:attach_session(target_id)”Attach to an existing target by ID. Returns a session ID.
browser:call_session(session_id, method, params)
Section titled “browser:call_session(session_id, method, params)”Call CDP method on a specific session.
browser:wait_session_event(session_id, event, [opts])
Section titled “browser:wait_session_event(session_id, event, [opts])”Wait for session-level events.
Context Methods
Section titled “Context Methods”Returned by browser:new_context().
context.id
Section titled “context.id”The unique string ID of the context.
context:attach([url])
Section titled “context:attach([url])”Creates a new page within this isolated context.
local ctx = browser:new_context()local page = ctx:attach("https://example.com")context:close()
Section titled “context:close()”Closes the context and all associated pages.
ctx:close()