fix: 修复质量检查发现的选择器与资源问题
修复浏览器通配符过滤和 ARIA 选择器转义,收敛表单窗口生命周期,释放邮件连接,清理日志复制定时器,并校准 Word COM 测试超时。
This commit is contained in:
1 parent
745da55e4e
commit
cc28d49ab5
7 files changed
+70
-43
No files matched your search
@@ -162,6 +162,10 @@ export class BrowserSession implements BrowserLike {
|
||||
const spec = selectorSpec(selector);
|
||||
const result = await this.evaluate<{ found: boolean; value?: T }>(`(() => {
|
||||
const spec = ${JSON.stringify(spec)};
|
||||
const escapeSelectorValue = (value) => {
|
||||
if (globalThis.CSS && typeof CSS.escape === 'function') return CSS.escape(String(value));
|
||||
return String(value).replace(/[^a-zA-Z0-9_-]/g, (char) => '\\\\' + char);
|
||||
};
|
||||
const find = () => {
|
||||
if (spec.kind === 'xpath') {
|
||||
return document.evaluate(spec.value, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
@@ -175,7 +179,7 @@ export class BrowserSession implements BrowserLike {
|
||||
return matches.sort((a, b) => (a.innerText || '').length - (b.innerText || '').length)[0] || null;
|
||||
}
|
||||
if (spec.kind === 'aria') {
|
||||
const role = spec.role || spec.value;
|
||||
const role = escapeSelectorValue(spec.role || spec.value);
|
||||
const name = spec.name || '';
|
||||
return [...document.querySelectorAll('[role="' + role + '"], ' + role)].find((node) => {
|
||||
const accessibleName = node.getAttribute('aria-label') || node.innerText || '';
|
||||
@@ -850,7 +854,7 @@ export class BrowserSession implements BrowserLike {
|
||||
if (options.url) {
|
||||
const keyword = options.url;
|
||||
captures = options.wildcard
|
||||
? captures.filter(c => new RegExp("^" + keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\ async currentUrl(): Promise<string> {").replace(/\*/g, ".*")).test(c.url))
|
||||
? captures.filter(c => new RegExp("^" + keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")).test(c.url))
|
||||
: captures.filter(c => c.url.includes(keyword));
|
||||
}
|
||||
const result: Array<Record<string, unknown>> = [];
|
||||
|
||||
Reference in new issue
Block a user