diff --git a/src/client/selectors.ts b/src/client/selectors.ts index b71ac27ea5..9819f3ad6a 100644 --- a/src/client/selectors.ts +++ b/src/client/selectors.ts @@ -17,12 +17,13 @@ import { evaluationScript } from './clientHelper'; import * as channels from '../protocol/channels'; import { ChannelOwner } from './channelOwner'; +import { SelectorEngine } from './types'; export class Selectors { private _channels = new Set(); private _registrations: channels.SelectorsRegisterParams[] = []; - async register(name: string, script: string | Function | { path?: string, content?: string }, options: { contentScript?: boolean } = {}): Promise { + async register(name: string, script: string | (() => SelectorEngine) | { path?: string, content?: string }, options: { contentScript?: boolean } = {}): Promise { const source = await evaluationScript(script, undefined, false); const params = { ...options, name, source }; for (const channel of this._channels) diff --git a/src/client/types.ts b/src/client/types.ts index 9891da5ef5..6cb7db2522 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -86,3 +86,19 @@ export type LaunchServerOptions = { port?: number, logger?: Logger, } & FirefoxUserPrefs; + +export type SelectorEngine = { + /** + * Creates a selector that matches given target when queried at the root. + * Can return undefined if unable to create one. + */ + create(root: HTMLElement, target: HTMLElement): string | undefined; + /** + * Returns the first element matching given selector in the root's subtree. + */ + query(root: HTMLElement, selector: string): HTMLElement | null; + /** + * Returns all elements matching given selector in the root's subtree. + */ + queryAll(root: HTMLElement, selector: string): HTMLElement[]; +};