browser
Interact with the browser.
Functions
browser.isAvailable
browser.tabs.query(): Promise<boolean>
Check if there’s a browser that can be used.
Example
browser.tabs.query
browser.tabs.query(options: QueryOptions): Promise<Tab[]>
Query all the browser tabs.
Example
browser.tabs.getActive
browser.tabs.getActive(): Promise<Tab | null>
Get the active tab of the browser. The tab this method returns is the active tab when the command starts running. To get the last active tab of the browser, use the browser.tabs.query
instead.
Classes
browser.tabs.Tab
Represents the browser tab.
browser.tabs.Tab.id
number
The tab id
browser.tabs.Tab.url
string
The tab URL
browser.tabs.Tab.title
string
The tab title
browser.tabs.Tab.active
boolean
Whether the tab is active or not
browser.tabs.Tab.isClosed
() => Promise<boolean>
Check if the tab is closed
browser.tabs.Tab.getDetail
() => Promise<TabDetail>
Get the latest tab detail. Because the url
, title
, and active
properties is not changed when the tab is updated on the actual browser, use this method to get the latest tab detail.
Example
browser.tabs.Tab.findElement
(selector: string) => Promise<ElementHandle | null>
Find the first element that matches the given selector.
Example
browser.tabs.Tab.findAllElements
(selector: string) => Promise<ElementHandle[]>
Find all elements that matches the given selector.
Example
browser.tabs.Tab.selectElement
(options?: SelectElementOptions) => Promise<{ selector: string; canceled: boolean }>
Let the user manually select an element in the browser tab
Example
browser.tabs.Tab.reload
() => Promise<void>
Reload the tab.
browser.tabs.Tab.click
() => Promise<void>
Click an element.
Example
browser.tabs.Tab.mouseDown
(selector: ElementSelector) => Promise<void>
Presses the mouse to targeted element.
browser.tabs.Tab.mouseUp
(selector: ElementSelector) => Promise<void>
Release the mouse from the targeted element.
browser.tabs.Tab.keyDown
(selector: ElementSelector, key: KeyboardKeys, options?: KeyDownOptions) => Promise<void>
Press key to the targeted element.
browser.tabs.Tab.keyUp
(selector: ElementSelector, key: KeyboardKeys, options?: KeyUpOptions) => Promise<void>
Release the key from the targeted element.
browser.tabs.Tab.press
(selector: ElementSelector, key: KeyboardKeys, options?: KeyUpOptions & KeyDownOptions) => Promise<void>
Press and release key to the targeted element.
Example
browser.tabs.Tab.type
(selector: ElementSelector, text: string, options?: KeyboardTypeOptions) => Promise<void>
Type the text character by character to the targeted element.
Example
browser.tabs.Tab.getText
(selector?: ElementSelector, options?: GetTextOptions) => Promise<string>
Get the element text, it will get the body text by default if the selector is not specified.
Example
browser.tabs.Tab.getHtml
(selector?: ElementSelector, options?: GetHTMLOptions) => Promise<string>
Get the element HTML, it will get the body HTML by default if the selector is not specified.
Example
browser.tabs.Tab.setAttributes
(selector?: ElementSelector, attrs: Record<string, string>) => Promise<string>
Set the element attribute.
Example
browser.tabs.Tab.getAttributes
(selector?: ElementSelector, attrNames?: string | string[]) => Promise<string | null | Record<string, string>>
Get the element attributes.
Example
browser.tabs.Tab.select
(selector?: ElementSelector, values: …string[]) => Promise<string[]>
Select options in the <select> tag. If the select element has the> multiple
attribute, all the values will selected, otherwise it only select the first value.
Example
browser.tabs.Tab.selectFile
(selector?: ElementSelector, files: (string | SelectFileData)[], options?: SelectFileOptions) => Promise<string[]>
Set the files in the <input type=“file” /> element or simulate drag and drop files into the browser. The string in the files
parameter is a file path.
Example
browser.tabs.Tab.waitForSelector
(selector: ElementSelector, options?: WaitForSelectorOptions) => Promise<ElementHandle | null>
Wait for an element until it matches the given state and selector
Example
Types
browser.tabs.SelectElementOptions
Options for the browser.tabs.Tab.selectElement
method.
Property | Type | Description |
---|---|---|
title | ?string | Title that will be shown to the user when selecting an element |
description | ?string | Description that will be shown to the user when selecting an element |
filter | SelectElementFilter | Filter for which element can be selected. |
browser.tabs.SelectElementFilter
Filter for which element can be selected.
Property | Type | Description |
---|---|---|
selector | ?string | The CSS Selector that the element must match |
browser.tabs.ElementHandle
Represents element as in the browser tab
The method in the element handle is pretty much the same as the one in the browser tabs type except the method that requires the ElementSelector
parameter doesn’t require it anymore..
browser.tabs.QueryOptions
Options for the browser.tabs.query
method.
Property | Type | Description |
---|---|---|
url | ?string | Match the tab url againts match patterns |
index | ?number | The tab position within their window |
title | ?string | Match the tab againts the tab title |
active | ?boolean | Whether the tab is active or not |
status | ?TabStatus | The status of the tab |
browser.tabs.GetHTMLOptions
Options for the getHTML
tab method.
Property | Type | Description |
---|---|---|
outerHTML | boolean | Capture the HTML of the element itself and its content |
browser.tabs.GetTextOptions
Options for the getText
tab method.
Property | Type | Description |
---|---|---|
onlyVisibleText | boolean | Only capture text that are visible |
browser.tabs.KeyboardKeys
Keyboard keys
browser.tabs.KeyboardModifiers
Keyboard modifiers
browser.tabs.KeyboardTypeOptions
Options for the type
tab method.
Property | Type | Description |
---|---|---|
delay | number | Delay in milliseconds when typing each key |
clearValue | boolean | Clear value of the targeted text field |
browser.tabs.KeyDownOptions
Options for the type
tab method.
Property | Type | Description |
---|---|---|
text | number | Text to send when pressing key |
modifiers | KeyboardModifiers[] | Keyboard modifiers |
browser.tabs.KeyUpOptions
Options for the type
tab method.
Property | Type | Description |
---|---|---|
delay | number | Delay in milliseconds before releasing key |
modifiers | KeyboardModifiers[] | Keyboard modifiers |
browser.tabs.ElementSelector
Selector to query element inside the tab.
Property | Type | Description |
---|---|---|
selector | string | Element selector |
elementIndex | ?number | Index of the element to select |
Inside the selector string, you can use either CSS Selector or XPath. You can write CSS Selector directly but for using the XPath you must use the ::xpath=
prefix.
Alt. app has a custom CSS Selector syntax that you can use:
>>
: Selecting an element inside a shadow DOM. For example,.element-a >> .element-b
Example
browser.tabs.TabStatus
The browser tab’s loading status
browser.tabs.SelectFileData
Data of the file to select.
Property | Type | Description |
---|---|---|
fileName | string | Name of the file. It should include the file extension |
mimeType | string | MIME type of the file |
lastModified | number | Last time the file is modified. The value must be in unix time |
browser.tabs.SelectFileOptions
Options for the browser.selectFile
method.
Property | Type | Description |
---|---|---|
action | ?('select' | 'drag-drop') | Which action to simulate when selecting a file. select to simulate the user selecting a file on the <input type="file" /> element. drag-drop simulates the user dragging and dropping the file into the element. |
browser.tabs.TabDetail
Contains information about the browser tab
browser.tabs.WaitForSelectorOptions
Options for the waitForSelector
tab method.
Property | Type | Description |
---|---|---|
timeout | ?number | How long it should be waiting in milliseconds. Default is 5000 |
state | 'attached' | 'detached' | 'visible' | 'hidden' | The state of the element. Default is visible |
Element state:
attached
: Element is available in the DOM tree.detached
: Element is detached from the DOM tree.visible
: Element is considered visible when:- The element size (height and width) is not zero
- The element doesn’t have
visibility: hidden
computed style - The element doesn’t have
display: none
computed style
hidden
: Element is not in the DOM tree or element is the opposite of thevisible
state