8
0
Просмотр исходного кода

Merge pull request #242 from ckeditor/t/ckeditor5/930

Fix: Error should not be thrown when scrolling the viewport from within an iframe in a different domain. Closes ckeditor/ckeditor5#930.
Piotrek Koszuliński 7 лет назад
Родитель
Сommit
40f4438fc9

+ 8 - 0
packages/ckeditor5-utils/src/dom/scroll.js

@@ -68,6 +68,14 @@ export function scrollViewportToShowTarget( { target, viewportOffset = 0 } ) {
 			// by it's iframe's position.
 			currentFrame = currentWindow.frameElement;
 			currentWindow = currentWindow.parent;
+
+			// If the current window has some parent but frameElement is inaccessible, then they have
+			// different domains/ports and, due to security reasons, accessing and scrolling
+			// the parent window won't be possible.
+			// See https://github.com/ckeditor/ckeditor5/issues/930.
+			if ( !currentFrame ) {
+				return;
+			}
 		} else {
 			currentWindow = null;
 		}

+ 9 - 0
packages/ckeditor5-utils/tests/dom/scroll.js

@@ -291,6 +291,15 @@ describe( 'scrollViewportToShowTarget()', () => {
 			sinon.assert.calledWithExactly( iframeWindow.scrollTo, 100, -100 );
 			sinon.assert.calledWithExactly( window.scrollTo, 1820, 1520 );
 		} );
+
+		// https://github.com/ckeditor/ckeditor5/issues/930
+		it( 'should not throw if the child frame has no access to the #frameElement of the parent', () => {
+			sinon.stub( iframeWindow, 'frameElement' ).get( () => null );
+
+			expect( () => {
+				scrollViewportToShowTarget( { target } );
+			} ).to.not.throw();
+		} );
 	} );
 
 	// Note: Because everything is a mock, scrolling the firstAncestor doesn't really change