2020-01-06 18:22:35 -08:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2019-11-21 14:43:30 -08:00
|
|
|
|
2020-05-15 15:21:49 -07:00
|
|
|
import { createAttributeEngine } from './attributeSelectorEngine';
|
|
|
|
import { createCSSEngine } from './cssSelectorEngine';
|
|
|
|
import { SelectorEngine, SelectorRoot } from './selectorEngine';
|
|
|
|
import { createTextSelector } from './textSelectorEngine';
|
|
|
|
import { XPathEngine } from './xpathSelectorEngine';
|
2020-12-04 06:51:18 -08:00
|
|
|
import { ParsedSelector, ParsedSelectorV1, parseSelector } from '../common/selectorParser';
|
2020-08-24 06:51:51 -07:00
|
|
|
import { FatalDOMError } from '../common/domErrors';
|
2020-12-04 06:51:18 -08:00
|
|
|
import { SelectorEvaluatorImpl, SelectorEngine as SelectorEngineV2, QueryContext } from './selectorEvaluator';
|
2019-12-16 20:49:18 -08:00
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
type Predicate<T> = (progress: InjectedScriptProgress, continuePolling: symbol) => T | symbol;
|
2019-11-22 15:36:17 -08:00
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
export type InjectedScriptProgress = {
|
|
|
|
aborted: boolean,
|
|
|
|
log: (message: string) => void,
|
|
|
|
logRepeating: (message: string) => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type InjectedScriptPoll<T> = {
|
|
|
|
result: Promise<T>,
|
|
|
|
// Takes more logs, waiting until at least one message is available.
|
|
|
|
takeNextLogs: () => Promise<string[]>,
|
|
|
|
// Takes all current logs without waiting.
|
|
|
|
takeLastLogs: () => string[],
|
|
|
|
cancel: () => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
export class InjectedScript {
|
2020-12-04 06:51:18 -08:00
|
|
|
private _enginesV1: Map<string, SelectorEngine>;
|
|
|
|
private _evaluator: SelectorEvaluatorImpl;
|
2020-05-15 15:21:49 -07:00
|
|
|
|
|
|
|
constructor(customEngines: { name: string, engine: SelectorEngine}[]) {
|
2020-12-04 06:51:18 -08:00
|
|
|
this._enginesV1 = new Map();
|
|
|
|
this._enginesV1.set('css', createCSSEngine(true));
|
|
|
|
this._enginesV1.set('css:light', createCSSEngine(false));
|
|
|
|
this._enginesV1.set('xpath', XPathEngine);
|
|
|
|
this._enginesV1.set('xpath:light', XPathEngine);
|
|
|
|
this._enginesV1.set('text', createTextSelector(true));
|
|
|
|
this._enginesV1.set('text:light', createTextSelector(false));
|
|
|
|
this._enginesV1.set('id', createAttributeEngine('id', true));
|
|
|
|
this._enginesV1.set('id:light', createAttributeEngine('id', false));
|
|
|
|
this._enginesV1.set('data-testid', createAttributeEngine('data-testid', true));
|
|
|
|
this._enginesV1.set('data-testid:light', createAttributeEngine('data-testid', false));
|
|
|
|
this._enginesV1.set('data-test-id', createAttributeEngine('data-test-id', true));
|
|
|
|
this._enginesV1.set('data-test-id:light', createAttributeEngine('data-test-id', false));
|
|
|
|
this._enginesV1.set('data-test', createAttributeEngine('data-test', true));
|
|
|
|
this._enginesV1.set('data-test:light', createAttributeEngine('data-test', false));
|
|
|
|
for (const { name, engine } of customEngines)
|
|
|
|
this._enginesV1.set(name, engine);
|
|
|
|
|
|
|
|
const wrapped = new Map<string, SelectorEngineV2>();
|
|
|
|
for (const { name, engine } of customEngines)
|
|
|
|
wrapped.set(name, wrapV2(name, engine));
|
|
|
|
this._evaluator = new SelectorEvaluatorImpl(wrapped);
|
2020-05-15 15:21:49 -07:00
|
|
|
}
|
|
|
|
|
2020-09-06 18:19:32 -07:00
|
|
|
parseSelector(selector: string): ParsedSelector {
|
|
|
|
return parseSelector(selector);
|
|
|
|
}
|
|
|
|
|
2020-06-11 18:18:33 -07:00
|
|
|
querySelector(selector: ParsedSelector, root: Node): Element | undefined {
|
2020-05-15 15:21:49 -07:00
|
|
|
if (!(root as any)['querySelector'])
|
|
|
|
throw new Error('Node is not queryable.');
|
2020-12-04 06:51:18 -08:00
|
|
|
if (selector.v1)
|
|
|
|
return this._querySelectorRecursivelyV1(root as SelectorRoot, selector.v1, 0);
|
|
|
|
return this._evaluator.evaluate({ scope: root as Document | Element, pierceShadow: true }, selector.v2!)[0];
|
2020-05-15 15:21:49 -07:00
|
|
|
}
|
|
|
|
|
2020-12-04 06:51:18 -08:00
|
|
|
private _querySelectorRecursivelyV1(root: SelectorRoot, selector: ParsedSelectorV1, index: number): Element | undefined {
|
2020-05-15 15:21:49 -07:00
|
|
|
const current = selector.parts[index];
|
|
|
|
if (index === selector.parts.length - 1)
|
2020-12-04 06:51:18 -08:00
|
|
|
return this._enginesV1.get(current.name)!.query(root, current.body);
|
|
|
|
const all = this._enginesV1.get(current.name)!.queryAll(root, current.body);
|
2020-05-15 15:21:49 -07:00
|
|
|
for (const next of all) {
|
2020-12-04 06:51:18 -08:00
|
|
|
const result = this._querySelectorRecursivelyV1(next, selector, index + 1);
|
2020-05-15 15:21:49 -07:00
|
|
|
if (result)
|
|
|
|
return selector.capture === index ? next : result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 18:18:33 -07:00
|
|
|
querySelectorAll(selector: ParsedSelector, root: Node): Element[] {
|
2020-05-15 15:21:49 -07:00
|
|
|
if (!(root as any)['querySelectorAll'])
|
|
|
|
throw new Error('Node is not queryable.');
|
2020-12-04 06:51:18 -08:00
|
|
|
if (selector.v1)
|
|
|
|
return this._querySelectorAllV1(selector.v1, root as SelectorRoot);
|
|
|
|
return this._evaluator.evaluate({ scope: root as Document | Element, pierceShadow: true }, selector.v2!);
|
|
|
|
}
|
|
|
|
|
|
|
|
private _querySelectorAllV1(selector: ParsedSelectorV1, root: SelectorRoot): Element[] {
|
2020-05-15 15:21:49 -07:00
|
|
|
const capture = selector.capture === undefined ? selector.parts.length - 1 : selector.capture;
|
|
|
|
// Query all elements up to the capture.
|
|
|
|
const partsToQuerAll = selector.parts.slice(0, capture + 1);
|
|
|
|
// Check they have a descendant matching everything after the capture.
|
|
|
|
const partsToCheckOne = selector.parts.slice(capture + 1);
|
|
|
|
let set = new Set<SelectorRoot>([ root as SelectorRoot ]);
|
|
|
|
for (const { name, body } of partsToQuerAll) {
|
|
|
|
const newSet = new Set<Element>();
|
|
|
|
for (const prev of set) {
|
2020-12-04 06:51:18 -08:00
|
|
|
for (const next of this._enginesV1.get(name)!.queryAll(prev, body)) {
|
2020-05-15 15:21:49 -07:00
|
|
|
if (newSet.has(next))
|
|
|
|
continue;
|
|
|
|
newSet.add(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
set = newSet;
|
|
|
|
}
|
|
|
|
const candidates = Array.from(set) as Element[];
|
|
|
|
if (!partsToCheckOne.length)
|
|
|
|
return candidates;
|
|
|
|
const partial = { parts: partsToCheckOne };
|
2020-12-04 06:51:18 -08:00
|
|
|
return candidates.filter(e => !!this._querySelectorRecursivelyV1(e, partial, 0));
|
2020-05-15 15:21:49 -07:00
|
|
|
}
|
|
|
|
|
2020-09-06 18:19:32 -07:00
|
|
|
extend(source: string, params: any): any {
|
|
|
|
const constrFunction = global.eval(source);
|
|
|
|
return new constrFunction(this, params);
|
|
|
|
}
|
|
|
|
|
2019-12-04 13:11:10 -08:00
|
|
|
isVisible(element: Element): boolean {
|
2020-04-27 15:40:46 -07:00
|
|
|
// Note: this logic should be similar to waitForDisplayedAtStablePosition() to avoid surprises.
|
2019-12-04 13:11:10 -08:00
|
|
|
if (!element.ownerDocument || !element.ownerDocument.defaultView)
|
|
|
|
return true;
|
|
|
|
const style = element.ownerDocument.defaultView.getComputedStyle(element);
|
|
|
|
if (!style || style.visibility === 'hidden')
|
|
|
|
return false;
|
|
|
|
const rect = element.getBoundingClientRect();
|
2020-04-27 15:40:46 -07:00
|
|
|
return rect.width > 0 && rect.height > 0;
|
2019-12-04 13:11:10 -08:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
pollRaf<T>(predicate: Predicate<T>): InjectedScriptPoll<T> {
|
2020-06-24 15:12:17 -07:00
|
|
|
return this._runAbortableTask(progress => {
|
|
|
|
let fulfill: (result: T) => void;
|
|
|
|
let reject: (error: Error) => void;
|
|
|
|
const result = new Promise<T>((f, r) => { fulfill = f; reject = r; });
|
|
|
|
|
|
|
|
const onRaf = () => {
|
|
|
|
if (progress.aborted)
|
|
|
|
return;
|
|
|
|
try {
|
|
|
|
const continuePolling = Symbol('continuePolling');
|
|
|
|
const success = predicate(progress, continuePolling);
|
|
|
|
if (success !== continuePolling)
|
|
|
|
fulfill(success as T);
|
|
|
|
else
|
|
|
|
requestAnimationFrame(onRaf);
|
|
|
|
} catch (e) {
|
|
|
|
reject(e);
|
|
|
|
}
|
|
|
|
};
|
2019-12-18 18:11:02 -08:00
|
|
|
|
2020-06-24 15:12:17 -07:00
|
|
|
onRaf();
|
|
|
|
return result;
|
|
|
|
});
|
2019-12-03 10:51:41 -08:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
pollInterval<T>(pollInterval: number, predicate: Predicate<T>): InjectedScriptPoll<T> {
|
2020-06-24 15:12:17 -07:00
|
|
|
return this._runAbortableTask(progress => {
|
|
|
|
let fulfill: (result: T) => void;
|
|
|
|
let reject: (error: Error) => void;
|
|
|
|
const result = new Promise<T>((f, r) => { fulfill = f; reject = r; });
|
|
|
|
|
|
|
|
const onTimeout = () => {
|
|
|
|
if (progress.aborted)
|
|
|
|
return;
|
|
|
|
try {
|
|
|
|
const continuePolling = Symbol('continuePolling');
|
|
|
|
const success = predicate(progress, continuePolling);
|
|
|
|
if (success !== continuePolling)
|
|
|
|
fulfill(success as T);
|
|
|
|
else
|
|
|
|
setTimeout(onTimeout, pollInterval);
|
|
|
|
} catch (e) {
|
|
|
|
reject(e);
|
|
|
|
}
|
|
|
|
};
|
2019-12-18 18:11:02 -08:00
|
|
|
|
2020-06-24 15:12:17 -07:00
|
|
|
onTimeout();
|
|
|
|
return result;
|
|
|
|
});
|
2019-12-03 10:51:41 -08:00
|
|
|
}
|
2020-02-19 09:34:57 -08:00
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
private _runAbortableTask<T>(task: (progess: InjectedScriptProgress) => Promise<T>): InjectedScriptPoll<T> {
|
2020-06-25 13:13:10 -07:00
|
|
|
let unsentLogs: string[] = [];
|
|
|
|
let takeNextLogsCallback: ((logs: string[]) => void) | undefined;
|
2020-11-16 14:11:55 -08:00
|
|
|
let taskFinished = false;
|
2020-06-25 13:13:10 -07:00
|
|
|
const logReady = () => {
|
|
|
|
if (!takeNextLogsCallback)
|
|
|
|
return;
|
|
|
|
takeNextLogsCallback(unsentLogs);
|
|
|
|
unsentLogs = [];
|
|
|
|
takeNextLogsCallback = undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
const takeNextLogs = () => new Promise<string[]>(fulfill => {
|
|
|
|
takeNextLogsCallback = fulfill;
|
2020-11-16 14:11:55 -08:00
|
|
|
if (unsentLogs.length || taskFinished)
|
2020-06-25 13:13:10 -07:00
|
|
|
logReady();
|
2020-06-01 15:48:23 -07:00
|
|
|
});
|
|
|
|
|
2020-06-10 18:45:18 -07:00
|
|
|
let lastLog = '';
|
2020-08-24 15:30:45 -07:00
|
|
|
const progress: InjectedScriptProgress = {
|
2020-06-24 15:12:17 -07:00
|
|
|
aborted: false,
|
2020-06-01 15:48:23 -07:00
|
|
|
log: (message: string) => {
|
2020-06-10 18:45:18 -07:00
|
|
|
lastLog = message;
|
2020-06-25 13:13:10 -07:00
|
|
|
unsentLogs.push(message);
|
2020-06-01 15:48:23 -07:00
|
|
|
logReady();
|
|
|
|
},
|
2020-06-10 18:45:18 -07:00
|
|
|
logRepeating: (message: string) => {
|
|
|
|
if (message !== lastLog)
|
|
|
|
progress.log(message);
|
|
|
|
},
|
2020-06-01 15:48:23 -07:00
|
|
|
};
|
|
|
|
|
2020-11-16 14:11:55 -08:00
|
|
|
const result = task(progress);
|
|
|
|
|
|
|
|
// After the task has finished, there should be no more logs.
|
|
|
|
// Release any pending `takeNextLogs` call, and do not block any future ones.
|
|
|
|
// This prevents non-finished protocol evaluation calls and memory leaks.
|
|
|
|
result.finally(() => {
|
|
|
|
taskFinished = true;
|
|
|
|
logReady();
|
|
|
|
});
|
|
|
|
|
2020-06-01 15:48:23 -07:00
|
|
|
return {
|
2020-06-25 13:13:10 -07:00
|
|
|
takeNextLogs,
|
2020-11-16 14:11:55 -08:00
|
|
|
result,
|
2020-06-24 15:12:17 -07:00
|
|
|
cancel: () => { progress.aborted = true; },
|
2020-06-25 13:13:10 -07:00
|
|
|
takeLastLogs: () => unsentLogs,
|
2020-06-01 15:48:23 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-25 07:06:20 -08:00
|
|
|
getElementBorderWidth(node: Node): { left: number; top: number; } {
|
|
|
|
if (node.nodeType !== Node.ELEMENT_NODE || !node.ownerDocument || !node.ownerDocument.defaultView)
|
|
|
|
return { left: 0, top: 0 };
|
|
|
|
const style = node.ownerDocument.defaultView.getComputedStyle(node as Element);
|
|
|
|
return { left: parseInt(style.borderLeftWidth || '', 10), top: parseInt(style.borderTopWidth || '', 10) };
|
|
|
|
}
|
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
selectOptions(node: Node, optionsToSelect: (Node | { value?: string, label?: string, index?: number })[]): string[] | 'error:notconnected' | FatalDOMError {
|
2020-11-11 15:33:23 -08:00
|
|
|
const element = this.findLabelTarget(node as Element);
|
|
|
|
if (!element || !element.isConnected)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notconnected';
|
2020-11-11 15:33:23 -08:00
|
|
|
if (element.nodeName.toLowerCase() !== 'select')
|
|
|
|
return 'error:notselect';
|
|
|
|
const select = element as HTMLSelectElement;
|
|
|
|
const options = Array.from(select.options);
|
|
|
|
select.value = undefined as any;
|
2020-02-25 07:06:20 -08:00
|
|
|
for (let index = 0; index < options.length; index++) {
|
|
|
|
const option = options[index];
|
|
|
|
option.selected = optionsToSelect.some(optionToSelect => {
|
|
|
|
if (optionToSelect instanceof Node)
|
|
|
|
return option === optionToSelect;
|
|
|
|
let matches = true;
|
|
|
|
if (optionToSelect.value !== undefined)
|
|
|
|
matches = matches && optionToSelect.value === option.value;
|
|
|
|
if (optionToSelect.label !== undefined)
|
|
|
|
matches = matches && optionToSelect.label === option.label;
|
|
|
|
if (optionToSelect.index !== undefined)
|
|
|
|
matches = matches && optionToSelect.index === index;
|
|
|
|
return matches;
|
|
|
|
});
|
2020-11-11 15:33:23 -08:00
|
|
|
if (option.selected && !select.multiple)
|
2020-02-25 07:06:20 -08:00
|
|
|
break;
|
|
|
|
}
|
2020-11-11 15:33:23 -08:00
|
|
|
select.dispatchEvent(new Event('input', { 'bubbles': true }));
|
|
|
|
select.dispatchEvent(new Event('change', { 'bubbles': true }));
|
2020-06-24 15:12:17 -07:00
|
|
|
return options.filter(option => option.selected).map(option => option.value);
|
2020-02-25 07:06:20 -08:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
waitForEnabledAndFill(node: Node, value: string): InjectedScriptPoll<FatalDOMError | 'error:notconnected' | 'needsinput' | 'done'> {
|
2020-06-24 15:12:17 -07:00
|
|
|
return this.pollRaf((progress, continuePolling) => {
|
2020-06-01 18:56:49 -07:00
|
|
|
if (node.nodeType !== Node.ELEMENT_NODE)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notelement';
|
2020-11-05 05:22:49 -08:00
|
|
|
const element = this.findLabelTarget(node as Element);
|
|
|
|
if (element && !element.isConnected)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notconnected';
|
2020-11-05 05:22:49 -08:00
|
|
|
if (!element || !this.isVisible(element)) {
|
2020-06-10 18:45:18 -07:00
|
|
|
progress.logRepeating(' element is not visible - waiting...');
|
2020-06-24 15:12:17 -07:00
|
|
|
return continuePolling;
|
2020-06-10 18:45:18 -07:00
|
|
|
}
|
2020-06-01 18:56:49 -07:00
|
|
|
if (element.nodeName.toLowerCase() === 'input') {
|
|
|
|
const input = element as HTMLInputElement;
|
2020-12-02 14:43:41 -08:00
|
|
|
const type = input.type.toLowerCase();
|
|
|
|
const kDateTypes = new Set(['date', 'time', 'datetime', 'datetime-local', 'month', 'week']);
|
2020-06-01 18:56:49 -07:00
|
|
|
const kTextInputTypes = new Set(['', 'email', 'number', 'password', 'search', 'tel', 'text', 'url']);
|
2020-06-24 15:12:17 -07:00
|
|
|
if (!kTextInputTypes.has(type) && !kDateTypes.has(type)) {
|
|
|
|
progress.log(` input of type "${type}" cannot be filled`);
|
|
|
|
return 'error:notfillableinputtype';
|
|
|
|
}
|
2020-06-01 18:56:49 -07:00
|
|
|
if (type === 'number') {
|
|
|
|
value = value.trim();
|
|
|
|
if (isNaN(Number(value)))
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notfillablenumberinput';
|
2020-06-01 18:56:49 -07:00
|
|
|
}
|
2020-06-10 18:45:18 -07:00
|
|
|
if (input.disabled) {
|
|
|
|
progress.logRepeating(' element is disabled - waiting...');
|
2020-06-24 15:12:17 -07:00
|
|
|
return continuePolling;
|
2020-06-10 18:45:18 -07:00
|
|
|
}
|
|
|
|
if (input.readOnly) {
|
|
|
|
progress.logRepeating(' element is readonly - waiting...');
|
2020-06-24 15:12:17 -07:00
|
|
|
return continuePolling;
|
2020-06-10 18:45:18 -07:00
|
|
|
}
|
2020-06-01 18:56:49 -07:00
|
|
|
if (kDateTypes.has(type)) {
|
|
|
|
value = value.trim();
|
|
|
|
input.focus();
|
|
|
|
input.value = value;
|
|
|
|
if (input.value !== value)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notvaliddate';
|
2020-06-01 18:56:49 -07:00
|
|
|
element.dispatchEvent(new Event('input', { 'bubbles': true }));
|
|
|
|
element.dispatchEvent(new Event('change', { 'bubbles': true }));
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'done'; // We have already changed the value, no need to input it.
|
2020-06-01 18:56:49 -07:00
|
|
|
}
|
|
|
|
} else if (element.nodeName.toLowerCase() === 'textarea') {
|
|
|
|
const textarea = element as HTMLTextAreaElement;
|
2020-06-10 18:45:18 -07:00
|
|
|
if (textarea.disabled) {
|
|
|
|
progress.logRepeating(' element is disabled - waiting...');
|
2020-06-24 15:12:17 -07:00
|
|
|
return continuePolling;
|
2020-06-10 18:45:18 -07:00
|
|
|
}
|
|
|
|
if (textarea.readOnly) {
|
|
|
|
progress.logRepeating(' element is readonly - waiting...');
|
2020-06-24 15:12:17 -07:00
|
|
|
return continuePolling;
|
2020-06-10 18:45:18 -07:00
|
|
|
}
|
2020-06-23 13:02:31 -07:00
|
|
|
} else if (!(element as HTMLElement).isContentEditable) {
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notfillableelement';
|
2020-04-07 10:07:06 -07:00
|
|
|
}
|
2020-06-23 13:02:31 -07:00
|
|
|
const result = this._selectText(element);
|
2020-06-24 15:12:17 -07:00
|
|
|
if (result === 'error:notvisible') {
|
2020-06-23 13:02:31 -07:00
|
|
|
progress.logRepeating(' element is not visible - waiting...');
|
2020-06-24 15:12:17 -07:00
|
|
|
return continuePolling;
|
2020-06-23 13:02:31 -07:00
|
|
|
}
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'needsinput'; // Still need to input the value.
|
2020-06-01 18:56:49 -07:00
|
|
|
});
|
2020-04-14 17:09:26 -07:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
waitForVisibleAndSelectText(node: Node): InjectedScriptPoll<FatalDOMError | 'error:notconnected' | 'done'> {
|
2020-06-24 15:12:17 -07:00
|
|
|
return this.pollRaf((progress, continuePolling) => {
|
2020-06-23 13:02:31 -07:00
|
|
|
if (node.nodeType !== Node.ELEMENT_NODE)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notelement';
|
2020-06-23 13:02:31 -07:00
|
|
|
if (!node.isConnected)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notconnected';
|
2020-06-23 13:02:31 -07:00
|
|
|
const element = node as Element;
|
|
|
|
if (!this.isVisible(element)) {
|
|
|
|
progress.logRepeating(' element is not visible - waiting...');
|
2020-06-24 15:12:17 -07:00
|
|
|
return continuePolling;
|
2020-06-23 13:02:31 -07:00
|
|
|
}
|
|
|
|
const result = this._selectText(element);
|
2020-06-24 15:12:17 -07:00
|
|
|
if (result === 'error:notvisible') {
|
2020-06-23 13:02:31 -07:00
|
|
|
progress.logRepeating(' element is not visible - waiting...');
|
2020-06-24 15:12:17 -07:00
|
|
|
return continuePolling;
|
2020-06-23 13:02:31 -07:00
|
|
|
}
|
2020-06-24 15:12:17 -07:00
|
|
|
return result;
|
2020-06-23 13:02:31 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-24 15:12:17 -07:00
|
|
|
private _selectText(element: Element): 'error:notvisible' | 'error:notconnected' | 'done' {
|
2020-04-14 17:09:26 -07:00
|
|
|
if (element.nodeName.toLowerCase() === 'input') {
|
|
|
|
const input = element as HTMLInputElement;
|
2020-02-25 07:06:20 -08:00
|
|
|
input.select();
|
|
|
|
input.focus();
|
2020-06-23 13:02:31 -07:00
|
|
|
return 'done';
|
2020-04-07 10:07:06 -07:00
|
|
|
}
|
|
|
|
if (element.nodeName.toLowerCase() === 'textarea') {
|
2020-02-25 07:06:20 -08:00
|
|
|
const textarea = element as HTMLTextAreaElement;
|
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
|
|
|
textarea.focus();
|
2020-06-23 13:02:31 -07:00
|
|
|
return 'done';
|
2020-04-07 10:07:06 -07:00
|
|
|
}
|
2020-06-14 17:24:45 -07:00
|
|
|
const range = element.ownerDocument.createRange();
|
2020-04-14 17:09:26 -07:00
|
|
|
range.selectNodeContents(element);
|
2020-06-14 17:24:45 -07:00
|
|
|
const selection = element.ownerDocument.defaultView!.getSelection();
|
2020-04-14 17:09:26 -07:00
|
|
|
if (!selection)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notvisible';
|
2020-04-14 17:09:26 -07:00
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
2020-06-23 13:02:31 -07:00
|
|
|
(element as HTMLElement | SVGElement).focus();
|
|
|
|
return 'done';
|
|
|
|
}
|
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
waitForNodeVisible(node: Node): InjectedScriptPoll<'error:notconnected' | 'done'> {
|
2020-06-24 15:12:17 -07:00
|
|
|
return this.pollRaf((progress, continuePolling) => {
|
2020-06-23 13:02:31 -07:00
|
|
|
const element = node.nodeType === Node.ELEMENT_NODE ? node as Element : node.parentElement;
|
|
|
|
if (!node.isConnected || !element)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notconnected';
|
2020-06-23 13:02:31 -07:00
|
|
|
if (!this.isVisible(element)) {
|
|
|
|
progress.logRepeating(' element is not visible - waiting...');
|
2020-06-24 15:12:17 -07:00
|
|
|
return continuePolling;
|
2020-06-23 13:02:31 -07:00
|
|
|
}
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'done';
|
2020-06-23 13:02:31 -07:00
|
|
|
});
|
2020-04-18 18:29:31 -07:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
waitForNodeHidden(node: Node): InjectedScriptPoll<'done'> {
|
2020-08-17 16:22:34 -07:00
|
|
|
return this.pollRaf((progress, continuePolling) => {
|
|
|
|
const element = node.nodeType === Node.ELEMENT_NODE ? node as Element : node.parentElement;
|
|
|
|
if (!node.isConnected || !element)
|
|
|
|
return 'done';
|
|
|
|
if (this.isVisible(element)) {
|
|
|
|
progress.logRepeating(' element is visible - waiting...');
|
|
|
|
return continuePolling;
|
|
|
|
}
|
|
|
|
return 'done';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
waitForNodeEnabled(node: Node): InjectedScriptPoll<'error:notconnected' | 'done'> {
|
2020-08-17 16:22:34 -07:00
|
|
|
return this.pollRaf((progress, continuePolling) => {
|
|
|
|
const element = node.nodeType === Node.ELEMENT_NODE ? node as Element : node.parentElement;
|
|
|
|
if (!node.isConnected || !element)
|
|
|
|
return 'error:notconnected';
|
|
|
|
if (this._isElementDisabled(element)) {
|
|
|
|
progress.logRepeating(' element is not enabled - waiting...');
|
|
|
|
return continuePolling;
|
|
|
|
}
|
|
|
|
return 'done';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
waitForNodeDisabled(node: Node): InjectedScriptPoll<'error:notconnected' | 'done'> {
|
2020-08-19 17:20:10 -07:00
|
|
|
return this.pollRaf((progress, continuePolling) => {
|
|
|
|
const element = node.nodeType === Node.ELEMENT_NODE ? node as Element : node.parentElement;
|
|
|
|
if (!node.isConnected || !element)
|
|
|
|
return 'error:notconnected';
|
|
|
|
if (!this._isElementDisabled(element)) {
|
|
|
|
progress.logRepeating(' element is enabled - waiting...');
|
|
|
|
return continuePolling;
|
|
|
|
}
|
|
|
|
return 'done';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-24 09:30:31 -07:00
|
|
|
focusNode(node: Node, resetSelectionIfNotFocused?: boolean): FatalDOMError | 'error:notconnected' | 'done' {
|
2020-04-18 18:29:31 -07:00
|
|
|
if (!node.isConnected)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notconnected';
|
|
|
|
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
|
|
return 'error:notelement';
|
2020-07-24 09:30:31 -07:00
|
|
|
const wasFocused = (node.getRootNode() as (Document | ShadowRoot)).activeElement === node && node.ownerDocument && node.ownerDocument.hasFocus();
|
2020-04-18 18:29:31 -07:00
|
|
|
(node as HTMLElement | SVGElement).focus();
|
2020-07-24 09:30:31 -07:00
|
|
|
|
|
|
|
if (resetSelectionIfNotFocused && !wasFocused && node.nodeName.toLowerCase() === 'input') {
|
|
|
|
try {
|
|
|
|
const input = node as HTMLInputElement;
|
|
|
|
input.setSelectionRange(0, 0);
|
|
|
|
} catch (e) {
|
|
|
|
// Some inputs do not allow selection.
|
|
|
|
}
|
|
|
|
}
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'done';
|
2020-02-25 07:06:20 -08:00
|
|
|
}
|
|
|
|
|
2020-11-05 05:22:49 -08:00
|
|
|
findLabelTarget(element: Element): Element | undefined {
|
|
|
|
return element.nodeName === 'LABEL' ? (element as HTMLLabelElement).control || undefined : element;
|
|
|
|
}
|
|
|
|
|
2020-02-25 07:06:20 -08:00
|
|
|
isCheckboxChecked(node: Node) {
|
|
|
|
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
|
|
throw new Error('Not a checkbox or radio button');
|
2020-11-05 05:22:49 -08:00
|
|
|
const element = node as Element;
|
2020-02-25 07:06:20 -08:00
|
|
|
if (element.getAttribute('role') === 'checkbox')
|
|
|
|
return element.getAttribute('aria-checked') === 'true';
|
2020-11-05 05:22:49 -08:00
|
|
|
const input = this.findLabelTarget(element);
|
|
|
|
if (!input || input.nodeName !== 'INPUT')
|
|
|
|
throw new Error('Not a checkbox or radio button');
|
|
|
|
if (!['radio', 'checkbox'].includes((input as HTMLInputElement).type.toLowerCase()))
|
|
|
|
throw new Error('Not a checkbox or radio button');
|
|
|
|
return (input as HTMLInputElement).checked;
|
2020-02-25 07:06:20 -08:00
|
|
|
}
|
|
|
|
|
2020-09-03 10:09:03 -07:00
|
|
|
setInputFiles(node: Node, payloads: { name: string, mimeType: string, buffer: string }[]) {
|
2020-04-16 10:25:28 -07:00
|
|
|
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
|
|
return 'Node is not of type HTMLElement';
|
|
|
|
const element: Element | undefined = node as Element;
|
|
|
|
if (element.nodeName !== 'INPUT')
|
|
|
|
return 'Not an <input> element';
|
|
|
|
const input = element as HTMLInputElement;
|
|
|
|
const type = (input.getAttribute('type') || '').toLowerCase();
|
|
|
|
if (type !== 'file')
|
|
|
|
return 'Not an input[type=file] element';
|
|
|
|
|
2020-09-03 10:09:03 -07:00
|
|
|
const files = payloads.map(file => {
|
|
|
|
const bytes = Uint8Array.from(atob(file.buffer), c => c.charCodeAt(0));
|
|
|
|
return new File([bytes], file.name, { type: file.mimeType });
|
|
|
|
});
|
2020-04-16 10:25:28 -07:00
|
|
|
const dt = new DataTransfer();
|
|
|
|
for (const file of files)
|
|
|
|
dt.items.add(file);
|
|
|
|
input.files = dt.files;
|
|
|
|
input.dispatchEvent(new Event('input', { 'bubbles': true }));
|
|
|
|
input.dispatchEvent(new Event('change', { 'bubbles': true }));
|
|
|
|
}
|
|
|
|
|
2020-10-23 16:06:51 -07:00
|
|
|
waitForDisplayedAtStablePosition(node: Node, rafOptions: { rafCount: number, useTimeout?: boolean }, waitForEnabled: boolean): InjectedScriptPoll<'error:notconnected' | 'done'> {
|
2020-08-24 15:30:45 -07:00
|
|
|
let lastRect: { x: number, y: number, width: number, height: number } | undefined;
|
2020-06-24 15:12:17 -07:00
|
|
|
let counter = 0;
|
|
|
|
let samePositionCounter = 0;
|
|
|
|
let lastTime = 0;
|
|
|
|
|
2020-10-23 16:06:51 -07:00
|
|
|
const predicate = (progress: InjectedScriptProgress, continuePolling: symbol) => {
|
2020-06-24 15:12:17 -07:00
|
|
|
// First raf happens in the same animation frame as evaluation, so it does not produce
|
|
|
|
// any client rect difference compared to synchronous call. We skip the synchronous call
|
|
|
|
// and only force layout during actual rafs as a small optimisation.
|
|
|
|
if (++counter === 1)
|
|
|
|
return continuePolling;
|
|
|
|
|
2020-04-16 15:38:41 -07:00
|
|
|
if (!node.isConnected)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notconnected';
|
2020-06-01 15:48:23 -07:00
|
|
|
const element = node.nodeType === Node.ELEMENT_NODE ? (node as Element) : node.parentElement;
|
|
|
|
if (!element)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notconnected';
|
|
|
|
|
|
|
|
// Drop frames that are shorter than 16ms - WebKit Win bug.
|
|
|
|
const time = performance.now();
|
2020-10-23 16:06:51 -07:00
|
|
|
if (rafOptions.rafCount > 1 && time - lastTime < 15)
|
2020-06-24 15:12:17 -07:00
|
|
|
return continuePolling;
|
|
|
|
lastTime = time;
|
|
|
|
|
|
|
|
// Note: this logic should be similar to isVisible() to avoid surprises.
|
|
|
|
const clientRect = element.getBoundingClientRect();
|
|
|
|
const rect = { x: clientRect.top, y: clientRect.left, width: clientRect.width, height: clientRect.height };
|
|
|
|
const samePosition = lastRect && rect.x === lastRect.x && rect.y === lastRect.y && rect.width === lastRect.width && rect.height === lastRect.height;
|
|
|
|
const isDisplayed = rect.width > 0 && rect.height > 0;
|
|
|
|
if (samePosition)
|
|
|
|
++samePositionCounter;
|
|
|
|
else
|
|
|
|
samePositionCounter = 0;
|
2020-10-23 16:06:51 -07:00
|
|
|
const isStable = samePositionCounter >= rafOptions.rafCount;
|
2020-06-24 15:12:17 -07:00
|
|
|
const isStableForLogs = isStable || !lastRect;
|
|
|
|
lastRect = rect;
|
|
|
|
|
|
|
|
const style = element.ownerDocument && element.ownerDocument.defaultView ? element.ownerDocument.defaultView.getComputedStyle(element) : undefined;
|
|
|
|
const isVisible = !!style && style.visibility !== 'hidden';
|
|
|
|
|
2020-08-17 16:22:34 -07:00
|
|
|
const isDisabled = waitForEnabled && this._isElementDisabled(element);
|
2020-06-24 15:12:17 -07:00
|
|
|
|
|
|
|
if (isDisplayed && isStable && isVisible && !isDisabled)
|
|
|
|
return 'done';
|
|
|
|
|
|
|
|
if (!isDisplayed || !isVisible)
|
|
|
|
progress.logRepeating(` element is not visible - waiting...`);
|
|
|
|
else if (!isStableForLogs)
|
|
|
|
progress.logRepeating(` element is moving - waiting...`);
|
|
|
|
else if (isDisabled)
|
|
|
|
progress.logRepeating(` element is disabled - waiting...`);
|
|
|
|
return continuePolling;
|
2020-10-23 16:06:51 -07:00
|
|
|
};
|
|
|
|
if (rafOptions.useTimeout)
|
|
|
|
return this.pollInterval(16, predicate);
|
|
|
|
else
|
|
|
|
return this.pollRaf(predicate);
|
2020-02-25 07:06:20 -08:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:30:45 -07:00
|
|
|
checkHitTargetAt(node: Node, point: { x: number, y: number }): 'error:notconnected' | 'done' | { hitTargetDescription: string } {
|
2020-08-14 14:48:36 -07:00
|
|
|
let element: Element | null | undefined = node.nodeType === Node.ELEMENT_NODE ? (node as Element) : node.parentElement;
|
2020-04-29 11:05:23 -07:00
|
|
|
if (!element || !element.isConnected)
|
2020-06-24 15:12:17 -07:00
|
|
|
return 'error:notconnected';
|
2020-05-19 16:27:56 -07:00
|
|
|
element = element.closest('button, [role=button]') || element;
|
2020-05-27 22:16:54 -07:00
|
|
|
let hitElement = this.deepElementFromPoint(document, point.x, point.y);
|
2020-08-14 14:48:36 -07:00
|
|
|
const hitParents: Element[] = [];
|
|
|
|
while (hitElement && hitElement !== element) {
|
|
|
|
hitParents.push(hitElement);
|
2020-04-29 11:05:23 -07:00
|
|
|
hitElement = this._parentElementOrShadowHost(hitElement);
|
2020-08-14 14:48:36 -07:00
|
|
|
}
|
|
|
|
if (hitElement === element)
|
|
|
|
return 'done';
|
|
|
|
const hitTargetDescription = this.previewNode(hitParents[0]);
|
|
|
|
// Root is the topmost element in the hitTarget's chain that is not in the
|
|
|
|
// element's chain. For example, it might be a dialog element that overlays
|
|
|
|
// the target.
|
|
|
|
let rootHitTargetDescription: string | undefined;
|
|
|
|
while (element) {
|
|
|
|
const index = hitParents.indexOf(element);
|
|
|
|
if (index !== -1) {
|
|
|
|
if (index > 1)
|
|
|
|
rootHitTargetDescription = this.previewNode(hitParents[index - 1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
element = this._parentElementOrShadowHost(element);
|
|
|
|
}
|
|
|
|
if (rootHitTargetDescription)
|
|
|
|
return { hitTargetDescription: `${hitTargetDescription} from ${rootHitTargetDescription} subtree` };
|
|
|
|
return { hitTargetDescription };
|
2020-02-25 07:06:20 -08:00
|
|
|
}
|
2020-03-25 14:08:46 -07:00
|
|
|
|
2020-04-23 14:58:37 -07:00
|
|
|
dispatchEvent(node: Node, type: string, eventInit: Object) {
|
|
|
|
let event;
|
|
|
|
eventInit = { bubbles: true, cancelable: true, composed: true, ...eventInit };
|
|
|
|
switch (eventType.get(type)) {
|
|
|
|
case 'mouse': event = new MouseEvent(type, eventInit); break;
|
|
|
|
case 'keyboard': event = new KeyboardEvent(type, eventInit); break;
|
|
|
|
case 'touch': event = new TouchEvent(type, eventInit); break;
|
|
|
|
case 'pointer': event = new PointerEvent(type, eventInit); break;
|
|
|
|
case 'focus': event = new FocusEvent(type, eventInit); break;
|
|
|
|
case 'drag': event = new DragEvent(type, eventInit); break;
|
|
|
|
default: event = new Event(type, eventInit); break;
|
|
|
|
}
|
|
|
|
node.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
|
2020-08-17 16:22:34 -07:00
|
|
|
private _isElementDisabled(element: Element): boolean {
|
|
|
|
const elementOrButton = element.closest('button, [role=button]') || element;
|
|
|
|
return ['BUTTON', 'INPUT', 'SELECT'].includes(elementOrButton.nodeName) && elementOrButton.hasAttribute('disabled');
|
|
|
|
}
|
|
|
|
|
2020-03-25 14:08:46 -07:00
|
|
|
private _parentElementOrShadowHost(element: Element): Element | undefined {
|
|
|
|
if (element.parentElement)
|
|
|
|
return element.parentElement;
|
|
|
|
if (!element.parentNode)
|
|
|
|
return;
|
|
|
|
if (element.parentNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE && (element.parentNode as ShadowRoot).host)
|
|
|
|
return (element.parentNode as ShadowRoot).host;
|
|
|
|
}
|
|
|
|
|
2020-05-27 22:16:54 -07:00
|
|
|
deepElementFromPoint(document: Document, x: number, y: number): Element | undefined {
|
2020-03-25 14:08:46 -07:00
|
|
|
let container: Document | ShadowRoot | null = document;
|
|
|
|
let element: Element | undefined;
|
|
|
|
while (container) {
|
|
|
|
const innerElement = container.elementFromPoint(x, y) as Element | undefined;
|
|
|
|
if (!innerElement || element === innerElement)
|
|
|
|
break;
|
|
|
|
element = innerElement;
|
|
|
|
container = element.shadowRoot;
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
}
|
2020-06-01 15:48:23 -07:00
|
|
|
|
2020-06-12 11:10:18 -07:00
|
|
|
previewNode(node: Node): string {
|
|
|
|
if (node.nodeType === Node.TEXT_NODE)
|
|
|
|
return oneLine(`#text=${node.nodeValue || ''}`);
|
|
|
|
if (node.nodeType !== Node.ELEMENT_NODE)
|
|
|
|
return oneLine(`<${node.nodeName.toLowerCase()} />`);
|
|
|
|
const element = node as Element;
|
|
|
|
|
2020-06-06 20:59:06 -07:00
|
|
|
const attrs = [];
|
|
|
|
for (let i = 0; i < element.attributes.length; i++) {
|
2020-06-12 11:10:18 -07:00
|
|
|
const { name, value } = element.attributes[i];
|
|
|
|
if (name === 'style')
|
|
|
|
continue;
|
|
|
|
if (!value && booleanAttributes.has(name))
|
|
|
|
attrs.push(` ${name}`);
|
|
|
|
else
|
|
|
|
attrs.push(` ${name}="${value}"`);
|
2020-06-06 20:59:06 -07:00
|
|
|
}
|
|
|
|
attrs.sort((a, b) => a.length - b.length);
|
|
|
|
let attrText = attrs.join('');
|
|
|
|
if (attrText.length > 50)
|
|
|
|
attrText = attrText.substring(0, 49) + '\u2026';
|
|
|
|
if (autoClosingTags.has(element.nodeName))
|
2020-06-12 11:10:18 -07:00
|
|
|
return oneLine(`<${element.nodeName.toLowerCase()}${attrText}/>`);
|
2020-06-06 20:59:06 -07:00
|
|
|
|
|
|
|
const children = element.childNodes;
|
|
|
|
let onlyText = false;
|
|
|
|
if (children.length <= 5) {
|
|
|
|
onlyText = true;
|
|
|
|
for (let i = 0; i < children.length; i++)
|
|
|
|
onlyText = onlyText && children[i].nodeType === Node.TEXT_NODE;
|
|
|
|
}
|
2020-06-12 11:10:18 -07:00
|
|
|
let text = onlyText ? (element.textContent || '') : (children.length ? '\u2026' : '');
|
2020-06-06 20:59:06 -07:00
|
|
|
if (text.length > 50)
|
|
|
|
text = text.substring(0, 49) + '\u2026';
|
2020-06-12 11:10:18 -07:00
|
|
|
return oneLine(`<${element.nodeName.toLowerCase()}${attrText}>${text}</${element.nodeName.toLowerCase()}>`);
|
2020-06-01 15:48:23 -07:00
|
|
|
}
|
2019-11-21 14:43:30 -08:00
|
|
|
}
|
2020-04-23 14:58:37 -07:00
|
|
|
|
2020-12-04 06:51:18 -08:00
|
|
|
function wrapV2(name: string, engine: SelectorEngine): SelectorEngineV2 {
|
|
|
|
return {
|
|
|
|
query(context: QueryContext, args: string[]): Element[] {
|
|
|
|
if (args.length !== 1 || typeof args[0] !== 'string')
|
|
|
|
throw new Error(`engine "${name}" expects a single string`);
|
|
|
|
return engine.queryAll(context.scope, args[0]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-06 20:59:06 -07:00
|
|
|
const autoClosingTags = new Set(['AREA', 'BASE', 'BR', 'COL', 'COMMAND', 'EMBED', 'HR', 'IMG', 'INPUT', 'KEYGEN', 'LINK', 'MENUITEM', 'META', 'PARAM', 'SOURCE', 'TRACK', 'WBR']);
|
2020-06-12 11:10:18 -07:00
|
|
|
const booleanAttributes = new Set(['checked', 'selected', 'disabled', 'readonly', 'multiple']);
|
|
|
|
|
|
|
|
function oneLine(s: string): string {
|
|
|
|
return s.replace(/\n/g, '↵').replace(/\t/g, '⇆');
|
|
|
|
}
|
2020-06-06 20:59:06 -07:00
|
|
|
|
2020-04-23 14:58:37 -07:00
|
|
|
const eventType = new Map<string, 'mouse'|'keyboard'|'touch'|'pointer'|'focus'|'drag'>([
|
|
|
|
['auxclick', 'mouse'],
|
|
|
|
['click', 'mouse'],
|
|
|
|
['dblclick', 'mouse'],
|
|
|
|
['mousedown','mouse'],
|
|
|
|
['mouseeenter', 'mouse'],
|
|
|
|
['mouseleave', 'mouse'],
|
|
|
|
['mousemove', 'mouse'],
|
|
|
|
['mouseout', 'mouse'],
|
|
|
|
['mouseover', 'mouse'],
|
|
|
|
['mouseup', 'mouse'],
|
|
|
|
['mouseleave', 'mouse'],
|
|
|
|
['mousewheel', 'mouse'],
|
|
|
|
|
|
|
|
['keydown', 'keyboard'],
|
|
|
|
['keyup', 'keyboard'],
|
|
|
|
['keypress', 'keyboard'],
|
|
|
|
['textInput', 'keyboard'],
|
|
|
|
|
|
|
|
['touchstart', 'touch'],
|
|
|
|
['touchmove', 'touch'],
|
|
|
|
['touchend', 'touch'],
|
|
|
|
['touchcancel', 'touch'],
|
|
|
|
|
|
|
|
['pointerover', 'pointer'],
|
|
|
|
['pointerout', 'pointer'],
|
|
|
|
['pointerenter', 'pointer'],
|
|
|
|
['pointerleave', 'pointer'],
|
|
|
|
['pointerdown', 'pointer'],
|
|
|
|
['pointerup', 'pointer'],
|
|
|
|
['pointermove', 'pointer'],
|
|
|
|
['pointercancel', 'pointer'],
|
|
|
|
['gotpointercapture', 'pointer'],
|
|
|
|
['lostpointercapture', 'pointer'],
|
|
|
|
|
|
|
|
['focus', 'focus'],
|
|
|
|
['blur', 'focus'],
|
|
|
|
|
|
|
|
['drag', 'drag'],
|
|
|
|
['dragstart', 'drag'],
|
|
|
|
['dragend', 'drag'],
|
|
|
|
['dragover', 'drag'],
|
|
|
|
['dragenter', 'drag'],
|
|
|
|
['dragleave', 'drag'],
|
|
|
|
['dragexit', 'drag'],
|
|
|
|
['drop', 'drag'],
|
|
|
|
]);
|
2020-08-24 15:30:45 -07:00
|
|
|
|
|
|
|
export default InjectedScript;
|