Skip to content

Commit 4e745c2

Browse files
committed
Fix a few possible reference errors in webview. fixes microsoft#20122
1 parent 29f8a93 commit 4e745c2

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/vs/workbench/parts/html/browser/webview-pre.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ document.addEventListener("DOMContentLoaded", function (event) {
4545

4646
// propagate focus
4747
ipcRenderer.on('focus', function () {
48-
getTarget().contentWindow.focus();
48+
const target = getTarget();
49+
if (target) {
50+
target.contentWindow.focus();
51+
}
4952
});
5053

5154
// update iframe-contents
@@ -109,10 +112,12 @@ document.addEventListener("DOMContentLoaded", function (event) {
109112
styleBody(newDocument.body);
110113

111114
const frame = getTarget();
112-
frame.setAttribute('id', '_oldTarget')
115+
if (frame) {
116+
frame.setAttribute('id', '_oldTarget');
117+
}
113118

114119
// keep current scrollTop around and use later
115-
const scrollTop = frame.contentDocument.body.scrollTop;
120+
const scrollTop = frame && frame.contentDocument && frame.contentDocument.body ? frame.contentDocument.body.scrollTop : 0;
116121

117122
const newFrame = document.createElement('iframe');
118123
newFrame.setAttribute('id', '_target');
@@ -144,7 +149,9 @@ document.addEventListener("DOMContentLoaded", function (event) {
144149
// Forward message to the embedded iframe
145150
ipcRenderer.on('message', function (event, data) {
146151
const target = getTarget();
147-
target.contentWindow.postMessage(data, 'file://');
152+
if (target) {
153+
target.contentWindow.postMessage(data, 'file://');
154+
}
148155
});
149156

150157
// forward messages from the embedded iframe

0 commit comments

Comments
 (0)