使用开发工具追踪 jQuery 中的错误

问题描述 投票:0回答:1

在 asp.NET WVC 应用程序中,打开的每个页面都会在 Edge DevTools 中引发相同的错误...

"stack": "Error: Failed to execute 'querySelector' on 'Document': ':has(*,:jqfake)' is not a valid selector.\n

...查找错误会建议一个具有整数的 ID。问题是,我如何追踪以找到有问题的项目?看起来很奇怪,它在每个页面上,所以必须与全局加载的东西相关。

这是 jQuery 3.7.1 和 Bootstrap 5

jquery devtools
1个回答
0
投票

这是 jQuery 的一部分,正在测试以确保正确解析

:has()
选择器:

https://github.com/jquery/jquery/blob/19716254877870ecd649272cadd00a0d0ff8be01/src/selector/support.js#L14

// Support: Chrome 105 - 111 only, Safari 15.4 - 16.3 only
// Make sure the `:has()` argument is parsed unforgivingly.
// We include `*` in the test to detect buggy implementations that are
// _selectively_ forgiving (specifically when the list includes at least
// one valid selector).
// Note that we treat complete lack of support for `:has()` as if it were
// spec-compliant support, which is fine because use of `:has()` in such
// environments will fail in the qSA path and fall back to jQuery traversal
// anyway.
try {
    document.querySelector( ":has(*,:jqfake)" );
    support.cssHas = false;
} catch ( e ) {
    support.cssHas = true;
}

既然您看到了错误,这意味着您的浏览器通过了此测试。

但是,由于异常已被捕获,您可能不应该在开发工具中看到它。您是否可能会暂停caught异常,而不仅仅是uncaught异常?

© www.soinside.com 2019 - 2024. All rights reserved.