mirror of https://github.com/gorhill/uBlock.git
Improve element picker/zapper's handling of shadow roots
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1850
This commit is contained in:
parent
560c81a585
commit
9ee8e7b607
|
@ -83,17 +83,18 @@ const getElementBoundingClientRect = function(elem) {
|
||||||
if ( rect.width !== 0 && rect.height !== 0 ) {
|
if ( rect.width !== 0 && rect.height !== 0 ) {
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
if ( elem.shadowRoot instanceof DocumentFragment ) {
|
||||||
|
return getElementBoundingClientRect(elem.shadowRoot);
|
||||||
|
}
|
||||||
|
|
||||||
let left = rect.left,
|
let left = rect.left,
|
||||||
right = rect.right,
|
right = left + rect.width,
|
||||||
top = rect.top,
|
top = rect.top,
|
||||||
bottom = rect.bottom;
|
bottom = top + rect.height;
|
||||||
|
|
||||||
for ( const child of elem.children ) {
|
for ( const child of elem.children ) {
|
||||||
rect = getElementBoundingClientRect(child);
|
rect = getElementBoundingClientRect(child);
|
||||||
if ( rect.width === 0 || rect.height === 0 ) {
|
if ( rect.width === 0 || rect.height === 0 ) { continue; }
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( rect.left < left ) { left = rect.left; }
|
if ( rect.left < left ) { left = rect.left; }
|
||||||
if ( rect.right > right ) { right = rect.right; }
|
if ( rect.right > right ) { right = rect.right; }
|
||||||
if ( rect.top < top ) { top = rect.top; }
|
if ( rect.top < top ) { top = rect.top; }
|
||||||
|
@ -101,8 +102,10 @@ const getElementBoundingClientRect = function(elem) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
bottom,
|
||||||
height: bottom - top,
|
height: bottom - top,
|
||||||
left,
|
left,
|
||||||
|
right,
|
||||||
top,
|
top,
|
||||||
width: right - left
|
width: right - left
|
||||||
};
|
};
|
||||||
|
@ -940,13 +943,14 @@ const zapElementAtPoint = function(mx, my, options) {
|
||||||
|
|
||||||
if ( elemToRemove instanceof Element === false ) { return; }
|
if ( elemToRemove instanceof Element === false ) { return; }
|
||||||
|
|
||||||
const getStyleValue = function(elem, prop) {
|
const getStyleValue = (elem, prop) => {
|
||||||
const style = window.getComputedStyle(elem);
|
const style = window.getComputedStyle(elem);
|
||||||
return style ? style[prop] : '';
|
return style ? style[prop] : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Heuristic to detect scroll-locking: remove such lock when detected.
|
// Heuristic to detect scroll-locking: remove such lock when detected.
|
||||||
let maybeScrollLocked = false;
|
let maybeScrollLocked = elemToRemove.shadowRoot instanceof DocumentFragment;
|
||||||
|
if ( maybeScrollLocked === false ) {
|
||||||
let elem = elemToRemove;
|
let elem = elemToRemove;
|
||||||
do {
|
do {
|
||||||
maybeScrollLocked =
|
maybeScrollLocked =
|
||||||
|
@ -954,6 +958,7 @@ const zapElementAtPoint = function(mx, my, options) {
|
||||||
getStyleValue(elem, 'position') === 'fixed';
|
getStyleValue(elem, 'position') === 'fixed';
|
||||||
elem = elem.parentElement;
|
elem = elem.parentElement;
|
||||||
} while ( elem !== null && maybeScrollLocked === false );
|
} while ( elem !== null && maybeScrollLocked === false );
|
||||||
|
}
|
||||||
if ( maybeScrollLocked ) {
|
if ( maybeScrollLocked ) {
|
||||||
const doc = document;
|
const doc = document;
|
||||||
if ( getStyleValue(doc.body, 'overflowY') === 'hidden' ) {
|
if ( getStyleValue(doc.body, 'overflowY') === 'hidden' ) {
|
||||||
|
|
Loading…
Reference in New Issue