Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit e1944b3

Browse files
committed
Fix extension browser action webview displaying no content when first opened
Fix #13633 via a workaround to hide and show the webview after the first time it is attached to a new WebContents. Also avoid flash of different sizes by only setting a new size once the page has finished load (success or fail).
1 parent 7370c81 commit e1944b3

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

app/renderer/components/main/popupWindow.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ const windowActions = require('../../../../js/actions/windowActions')
1818

1919
// Styles
2020
const globalStyles = require('../styles/global')
21+
const shouldDebugWebviewEvents = false
22+
const waitForFrame = () => new Promise(resolve => window.requestAnimationFrame(resolve))
23+
24+
async function forceDrawWebview (webview) {
25+
await waitForFrame()
26+
webview.style.visibility = 'hidden'
27+
await waitForFrame()
28+
webview.style.visibility = ''
29+
await waitForFrame()
30+
}
2131

2232
class PopupWindow extends React.Component {
2333
constructor (props) {
@@ -47,8 +57,39 @@ class PopupWindow extends React.Component {
4757
})
4858
webview.addEventListener('did-attach', () => {
4959
webview.enablePreferredSizeMode(true)
60+
// Workaround first-draw blankness by forcing hide and show.
61+
if (!this.hasDrawn) {
62+
forceDrawWebview(webview)
63+
this.hasDrawn = true
64+
}
65+
})
66+
webview.addEventListener('load-start', () => {
67+
if (shouldDebugWebviewEvents) {
68+
console.log('load-start')
69+
}
70+
})
71+
webview.addEventListener('did-finish-load', () => {
72+
if (shouldDebugWebviewEvents) {
73+
console.log('did-finish-load')
74+
}
75+
windowActions.setPopupWindowLoaded()
76+
})
77+
webview.addEventListener('did-fail-load', () => {
78+
if (shouldDebugWebviewEvents) {
79+
console.log('did-fail-load')
80+
}
81+
windowActions.setPopupWindowLoaded()
82+
})
83+
webview.addEventListener('did-fail-provisional-load', () => {
84+
if (shouldDebugWebviewEvents) {
85+
console.log('did-fail-provisional-load')
86+
}
87+
windowActions.setPopupWindowLoaded()
5088
})
5189
webview.addEventListener('preferred-size-changed', () => {
90+
if (shouldDebugWebviewEvents) {
91+
console.log('preferred-size-changed')
92+
}
5293
webview.getPreferredSize((preferredSize) => {
5394
const width = preferredSize.width
5495
const height = preferredSize.height
@@ -84,6 +125,7 @@ class PopupWindow extends React.Component {
84125
props.height = parseInt(detail.get('height'))
85126
props.top = parseInt(detail.get('top'))
86127
props.left = parseInt(detail.get('left'))
128+
props.loaded = detail.get('didFinishLoad')
87129

88130
// used in other functions
89131
props.src = detail.get('src')
@@ -122,6 +164,7 @@ class PopupWindow extends React.Component {
122164
data-popup-window
123165
className={css(
124166
styles.popupWindow,
167+
!this.props.loaded && styles.popupWindow_notLoaded,
125168
style.right !== undefined && styles.popupWindow_reverseExpand
126169
)}
127170
style={style} />
@@ -145,6 +188,10 @@ const styles = StyleSheet.create({
145188
zIndex: globalStyles.zindex.zindexPopupWindow
146189
},
147190

191+
popupWindow_notLoaded: {
192+
opacity: 0
193+
},
194+
148195
popupWindow_reverseExpand: {
149196
flexDirection: 'row-reverse'
150197
}

js/actions/windowActions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,12 @@ const windowActions = {
520520
})
521521
},
522522

523+
setPopupWindowLoaded: function () {
524+
dispatch({
525+
actionType: windowConstants.WINDOW_SET_POPUP_WINDOW_LOADED
526+
})
527+
},
528+
523529
/**
524530
* Dispatches a message to indicate that the frame should be muted
525531
*

js/constants/windowConstants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const windowConstants = {
4444
WINDOW_SET_CONTEXT_MENU_DETAIL: _, // If set, also indicates that the context menu is shown
4545
WINDOW_SET_CONTEXT_MENU_SELECTED_INDEX: _,
4646
WINDOW_SET_POPUP_WINDOW_DETAIL: _, // If set, also indicates that the popup window is shown
47+
WINDOW_SET_POPUP_WINDOW_LOADED: _,
4748
WINDOW_HIDE_BOOKMARK_HANGER: _,
4849
WINDOW_SET_AUDIO_MUTED: _,
4950
WINDOW_SET_FAVICON: _,

js/stores/windowStore.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,16 @@ const doAction = (action) => {
509509
if (!action.detail) {
510510
windowState = windowState.delete('popupWindowDetail')
511511
} else {
512+
const alreadyFinishedLoad = windowState.getIn(['popupWindowDetail', 'didFinishLoad'])
512513
windowState = windowState.set('popupWindowDetail', action.detail)
514+
if (alreadyFinishedLoad) {
515+
windowState = windowState.setIn(['popupWindowDetail', 'didFinishLoad'], true)
516+
}
517+
}
518+
break
519+
case windowConstants.WINDOW_SET_POPUP_WINDOW_LOADED:
520+
if (windowState.has('popupWindowDetail')) {
521+
windowState = windowState.setIn(['popupWindowDetail', 'didFinishLoad'], true)
513522
}
514523
break
515524
case windowConstants.WINDOW_SET_AUDIO_MUTED:

0 commit comments

Comments
 (0)