🌐 AI搜索 & 代理 主页
Skip to content

Commit 686f2c7

Browse files
committed
Selector: Use shallow equality to compare documents to avoid IE/Edge crashes
IE/Edge sometimes crash when comparing documents between frames using the strict equality operator (`===` & `!==`). Funnily enough, shallow comparisons (`==` & `!=`) work without crashing. Fixes gh-4441
1 parent 29a9544 commit 686f2c7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/selector.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ function find( selector, context, results, seed ) {
173173
// Try to shortcut find operations (as opposed to filters) in HTML documents
174174
if ( !seed ) {
175175

176-
if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
176+
// Support: IE 11+, Edge 17 - 18+
177+
// IE/Edge sometimes throw a "Permission denied" error when strict-comparing
178+
// two documents; shallow comparisons work.
179+
// eslint-disable-next-line eqeqeq
180+
if ( ( context ? context.ownerDocument || context : preferredDoc ) != document ) {
177181
setDocument( context );
178182
}
179183
context = context || document;
@@ -425,7 +429,11 @@ function setDocument( node ) {
425429
doc = node ? node.ownerDocument || node : preferredDoc;
426430

427431
// Return early if doc is invalid or already selected
428-
if ( doc === document || doc.nodeType !== 9 ) {
432+
// Support: IE 11+, Edge 17 - 18+
433+
// IE/Edge sometimes throw a "Permission denied" error when strict-comparing
434+
// two documents; shallow comparisons work.
435+
// eslint-disable-next-line eqeqeq
436+
if ( doc == document || doc.nodeType !== 9 ) {
429437
return;
430438
}
431439

0 commit comments

Comments
 (0)