Skip to content

Commit

Permalink
Remove try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Jul 5, 2021
1 parent 6b8c5db commit 07d3cf0
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/widgets/src/blocks/legacy-widget/edit/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export default function Preview( { idBase, instance, isVisible } ) {
// Only set height if the iframe is loaded,
// or it will grow to an unexpected large height in Safari if it's hidden initially.
if ( isLoaded ) {
// If the preview frame has another origin then this won't work.
// One possible solution is to add custom script to call `postMessage` in the preview frame.
// Or, better yet, we migrate away from iframe.
function setHeight() {
// Pick the maximum of these two values to account for margin collapsing.
const height = Math.max(
Expand Down Expand Up @@ -104,13 +107,8 @@ export default function Preview( { idBase, instance, isVisible } ) {
// such as negative margins in the Gallery Legacy Widget.
// It can't be scrolled anyway.
// TODO: Ideally, this should be fixed in core.
try {
event.target.contentDocument.body.style.overflow =
'hidden';
} catch {
// There might be permission error when trying to access cross-origin iframes.
// As a progressive enhancement, simply ignore the errors here.
}
event.target.contentDocument.body.style.overflow =
'hidden';

setIsLoaded( true );
} }
Expand Down

0 comments on commit 07d3cf0

Please sign in to comment.