Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
weizman committed Oct 27, 2024
1 parent ef04847 commit 8f7b09f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/hook.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const workaroundChromiumBug = require('./chromium_bug_workaround');
const {getLength} = require('./common');
const {shadows, toArray, getFramesArray, getContentWindowOfFrame, getOwnerWindowOfNode} = require('./utils');
const {Object, getFrameElement, Function} = require('./natives');
const {Object, getFrameElement, Function, isConnected} = require('./natives');
const {forEachOpened} = require('./proxy');

function isCrossOrigin(dst, src) {
Expand All @@ -24,6 +24,9 @@ function findWin(win, frameElement) {
}
for (let i = 0; i < shadows.length; i++) {
const shadow = shadows[i];
if (!isConnected(shadow)) {
continue;
}
const owner = getOwnerWindowOfNode(shadow);
if (owner !== win) {
continue;
Expand All @@ -32,9 +35,6 @@ function findWin(win, frameElement) {
for (let j = 0; j < frames.length; j++) {
const frame = frames[j];
const win = getContentWindowOfFrame(frame);
if (win === null) {
continue;
}
if (frame === frameElement) {
return win;
}
Expand Down
6 changes: 6 additions & 0 deletions src/natives.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function setup(win) {
push: Object.getOwnPropertyDescriptor(Array.prototype, 'push').value,
split: Object.getOwnPropertyDescriptor(String.prototype, 'split').value,
nodeType: Object.getOwnPropertyDescriptor(Node.prototype, 'nodeType').get,
isConnected: Object.getOwnPropertyDescriptor(Node.prototype, 'isConnected').get,
tagName: Object.getOwnPropertyDescriptor(Element.prototype, 'tagName').get,
getInnerHTML: Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML').get,
setInnerHTML: Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML').set,
Expand Down Expand Up @@ -137,6 +138,7 @@ function setup(win) {
push,
split,
nodeType,
isConnected,
tagName,
toString,
getOnload,
Expand Down Expand Up @@ -207,6 +209,10 @@ function setup(win) {
return bag.nodeType.call(node);
}

function isConnected(node) {
return bag.isConnected.call(node);
}

function tagName(element) {
return bag.tagName.call(element);
}
Expand Down
4 changes: 2 additions & 2 deletions src/shadow.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const hook = require('./hook');
const {getFramesArray, shadows} = require('./utils');
const {Object, Function} = require('./natives');
const {Object, Function, isConnected} = require('./natives');

function protectShadows(connectedOnly) {
for (let i = 0; i < shadows.length; i++) {
const shadow = shadows[i];
if (connectedOnly && !shadow.isConnected) {
if (connectedOnly && !isConnected(shadow)) {
continue;
}
const frames = getFramesArray(shadow, false);
Expand Down

0 comments on commit 8f7b09f

Please sign in to comment.